-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create @babel/helper-get-call-context package
- Loading branch information
1 parent
dc5316e
commit e090927
Showing
21 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
test | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# @babel/helper-get-call-context | ||
|
||
> Helper function to get the context of a CallExpression | ||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/helper-get-call-context | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/helper-get-call-context --dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@babel/helper-get-call-context", | ||
"version": "7.9.6", | ||
"description": "Helper function to get call context", | ||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-get-call-context", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
"@babel/traverse": "^7.9.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { NodePath } from "@babel/traverse"; | ||
|
||
export default function(callPath: NodePath): NodePath { | ||
callPath.assertCallExpression(); | ||
|
||
let calleePath = callPath.get("callee"); | ||
|
||
while ( | ||
calleePath.isTSAsExpression() || | ||
calleePath.isTypeCastExpression() || | ||
calleePath.isTSTypeAssertion() || | ||
calleePath.isParenthesizedExpression() | ||
) { | ||
calleePath = calleePath.get("expression"); | ||
} | ||
|
||
return calleePath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-spread/test/fixtures/call-context/flow-type-cast/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(a.b: any)(...args) |
7 changes: 7 additions & 0 deletions
7
...ages/babel-plugin-transform-spread/test/fixtures/call-context/flow-type-cast/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"flow" | ||
] | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-spread/test/fixtures/call-context/flow-type-cast/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var _a; | ||
|
||
(_a = a).b.apply(_a, babelHelpers.toConsumableArray(args)); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-spread/test/fixtures/call-context/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["external-helpers", "transform-spread", "transform-parameters"] | ||
} |
1 change: 1 addition & 0 deletions
1
...bel-plugin-transform-spread/test/fixtures/call-context/parenthesized-expressions/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(a.b)(...args) |
5 changes: 5 additions & 0 deletions
5
...plugin-transform-spread/test/fixtures/call-context/parenthesized-expressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"parserOpts": { | ||
"createParenthesizedExpressions": true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...el-plugin-transform-spread/test/fixtures/call-context/parenthesized-expressions/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var _a; | ||
|
||
((_a = a).b.apply)(_a, babelHelpers.toConsumableArray(args)); |
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-spread/test/fixtures/call-context/ts-as-class-field/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class A { | ||
#x; | ||
|
||
fn() { | ||
(this.#x as any)(...args); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...s/babel-plugin-transform-spread/test/fixtures/call-context/ts-as-class-field/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"typescript" | ||
] | ||
], | ||
"plugins": [ | ||
[ | ||
"proposal-class-properties" | ||
] | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
...ages/babel-plugin-transform-spread/test/fixtures/call-context/ts-as-class-field/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = privateMap.get(receiver); if (!descriptor) { throw new TypeError("attempted to get private field on non-instance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } | ||
|
||
class A { | ||
constructor() { | ||
_x.set(this, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
} | ||
|
||
fn() { | ||
_classPrivateFieldGet(this, _x)(...args); | ||
} | ||
|
||
} | ||
|
||
var _x = new WeakMap(); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-spread/test/fixtures/call-context/ts-type-cast/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(<any> a.b)(...args) |
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-spread/test/fixtures/call-context/ts-type-cast/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"typescript" | ||
] | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-spread/test/fixtures/call-context/ts-type-cast/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var _a; | ||
|
||
(_a = a).b.apply(_a, babelHelpers.toConsumableArray(args)); |
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-transform-spread/test/fixtures/regression/11400/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(dog.bark as any)(...args) | ||
(dog.bark as any)(...args) |
10 changes: 5 additions & 5 deletions
10
packages/babel-plugin-transform-spread/test/fixtures/regression/11400/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"typescript" | ||
] | ||
"presets": [ | ||
[ | ||
"typescript" | ||
] | ||
} | ||
] | ||
} |