New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add @babel/helper-validator-identifier #11289
Merged
nicolo-ribaudo
merged 5 commits into
babel:master
from
JLHwung:helper-validator-identifier
Mar 20, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c46257
refactor: replace esutils.keywords.isIdentifierNameES6 by helper-vali…
JLHwung ebc7d93
refactor: replace esutils isReservedWordES6 by isKeyword || isReserve…
JLHwung 153c057
address review comments
JLHwung 206d006
chore: specify both “main” and “exports”
JLHwung 8b34e8e
build helper-validator-identifier before babel-types
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following practice from https://github.com/nodejs/node/pull/32098/files#diff-8e67f407bc32a0569e25d7ecaff6e494R208
"exports": string
is supported on every version of node.js 13.