Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of
this
&co in computed keys in arrows transform (#14005)
- Loading branch information
1 parent
8936501
commit 36a5ac4
Showing
20 changed files
with
286 additions
and
117 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
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
4 changes: 2 additions & 2 deletions
4
packages/babel-helper-create-class-features-plugin/src/misc.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
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,19 @@ | ||
# @babel/helper-environment-visitor | ||
|
||
> Helper visitor to only visit nodes in the current 'this' context | ||
See our website [@babel/helper-environment-visitor](https://babeljs.io/docs/en/babel-helper-environment-visitor) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/helper-environment-visitor | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/helper-environment-visitor --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,29 @@ | ||
{ | ||
"name": "@babel/helper-environment-visitor", | ||
"version": "7.16.0", | ||
"description": "Helper visitor to only visit nodes in the current 'this' context", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/babel/babel.git", | ||
"directory": "packages/babel-helper-environment-visitor" | ||
}, | ||
"homepage": "https://babel.dev/docs/en/next/babel-helper-environment-visitor", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./lib/index.js", | ||
"exports": { | ||
".": "./lib/index.js" | ||
}, | ||
"dependencies": { | ||
"@babel/types": "workspace:^" | ||
}, | ||
"devDependencies": { | ||
"@babel/traverse": "workspace:^" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)" | ||
} |
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,38 @@ | ||
import type { NodePath } from "@babel/traverse"; | ||
import { VISITOR_KEYS, staticBlock } from "@babel/types"; | ||
import type * as t from "@babel/types"; | ||
|
||
// TODO (Babel 8): Don't export this function. | ||
export function skipAllButComputedKey( | ||
path: NodePath<t.Method | t.ClassProperty>, | ||
) { | ||
// If the path isn't computed, just skip everything. | ||
if (!path.node.computed) { | ||
path.skip(); | ||
return; | ||
} | ||
|
||
// So it's got a computed key. Make sure to skip every other key the | ||
// traversal would visit. | ||
const keys = VISITOR_KEYS[path.type]; | ||
for (const key of keys) { | ||
if (key !== "key") path.skipKey(key); | ||
} | ||
} | ||
|
||
// Methods are handled by the Method visitor; arrows are not skipped because they inherit the context. | ||
const skipKey = process.env.BABEL_8_BREAKING | ||
? "StaticBlock|ClassPrivateProperty|TypeAnnotation|FunctionDeclaration|FunctionExpression" | ||
: (staticBlock ? "StaticBlock|" : "") + | ||
"ClassPrivateProperty|TypeAnnotation|FunctionDeclaration|FunctionExpression"; | ||
|
||
// environmentVisitor should be used when traversing the whole class and not for specific class elements/methods. | ||
// For perf reasons, the environmentVisitor might be traversed with `{ noScope: true }`, which means `path.scope` is undefined. | ||
// Avoid using `path.scope` here | ||
export default { | ||
[skipKey]: path => path.skip(), | ||
|
||
"Method|ClassProperty"(path: NodePath<t.Method | t.ClassProperty>) { | ||
skipAllButComputedKey(path); | ||
}, | ||
}; |
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
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
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
5 changes: 2 additions & 3 deletions
5
packages/babel-plugin-transform-classes/src/transformClass.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
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
Oops, something went wrong.