-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @babel/helper-validator-identifier (#11289)
* refactor: replace esutils.keywords.isIdentifierNameES6 by helper-validator-identifier * refactor: replace esutils isReservedWordES6 by isKeyword || isReservedWord * address review comments * chore: specify both “main” and “exports” * build helper-validator-identifier before babel-types
- Loading branch information
Showing
21 changed files
with
304 additions
and
169 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
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
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-validator-identifier | ||
|
||
> Validate identifier/keywords name | ||
See our website [@babel/helper-validator-identifier](https://babeljs.io/docs/en/next/babel-helper-validator-identifier.html) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/helper-validator-identifier | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/helper-validator-identifier --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,17 @@ | ||
{ | ||
"name": "@babel/helper-validator-identifier", | ||
"version": "7.9.0", | ||
"description": "Validate identifier/keywords name", | ||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-validator-identifier", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./lib/index.js", | ||
"exports": "./lib/index.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"charcodes": "^0.2.0", | ||
"unicode-13.0.0": "^0.8.0" | ||
} | ||
} |
File renamed without changes.
102 changes: 102 additions & 0 deletions
102
packages/babel-helper-validator-identifier/src/identifier.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
export { | ||
isIdentifierName, | ||
isIdentifierChar, | ||
isIdentifierStart, | ||
} from "./identifier"; | ||
export { | ||
isReservedWord, | ||
isStrictBindOnlyReservedWord, | ||
isStrictBindReservedWord, | ||
isStrictReservedWord, | ||
isKeyword, | ||
} from "./keyword"; |
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,98 @@ | ||
// @flow | ||
|
||
const reservedWords = { | ||
keyword: [ | ||
"break", | ||
"case", | ||
"catch", | ||
"continue", | ||
"debugger", | ||
"default", | ||
"do", | ||
"else", | ||
"finally", | ||
"for", | ||
"function", | ||
"if", | ||
"return", | ||
"switch", | ||
"throw", | ||
"try", | ||
"var", | ||
"const", | ||
"while", | ||
"with", | ||
"new", | ||
"this", | ||
"super", | ||
"class", | ||
"extends", | ||
"export", | ||
"import", | ||
"null", | ||
"true", | ||
"false", | ||
"in", | ||
"instanceof", | ||
"typeof", | ||
"void", | ||
"delete", | ||
], | ||
strict: [ | ||
"implements", | ||
"interface", | ||
"let", | ||
"package", | ||
"private", | ||
"protected", | ||
"public", | ||
"static", | ||
"yield", | ||
], | ||
strictBind: ["eval", "arguments"], | ||
}; | ||
const keywords = new Set(reservedWords.keyword); | ||
const reservedWordsStrictSet = new Set(reservedWords.strict); | ||
const reservedWordsStrictBindSet = new Set(reservedWords.strictBind); | ||
|
||
/** | ||
* Checks if word is a reserved word in non-strict mode | ||
*/ | ||
export function isReservedWord(word: string, inModule: boolean): boolean { | ||
return (inModule && word === "await") || word === "enum"; | ||
} | ||
|
||
/** | ||
* Checks if word is a reserved word in non-binding strict mode | ||
* | ||
* Includes non-strict reserved words | ||
*/ | ||
export function isStrictReservedWord(word: string, inModule: boolean): boolean { | ||
return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word); | ||
} | ||
|
||
/** | ||
* Checks if word is a reserved word in binding strict mode, but it is allowed as | ||
* a normal identifier. | ||
*/ | ||
export function isStrictBindOnlyReservedWord(word: string): boolean { | ||
return reservedWordsStrictBindSet.has(word); | ||
} | ||
|
||
/** | ||
* Checks if word is a reserved word in binding strict mode | ||
* | ||
* Includes non-strict reserved words and non-binding strict reserved words | ||
*/ | ||
export function isStrictBindReservedWord( | ||
word: string, | ||
inModule: boolean, | ||
): boolean { | ||
return ( | ||
isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word) | ||
); | ||
} | ||
|
||
export function isKeyword(word: string): boolean { | ||
return keywords.has(word); | ||
} |
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
Oops, something went wrong.