| 1 |
import isValidIdentifier from "./isValidIdentifier"; |
| 2 |
|
| 3 |
const RESERVED_WORDS_ES3_ONLY: Set<string> = new Set([ |
| 4 |
"abstract", |
| 5 |
"boolean", |
| 6 |
"byte", |
| 7 |
"char", |
| 8 |
"double", |
| 9 |
"enum", |
| 10 |
"final", |
| 11 |
"float", |
| 12 |
"goto", |
| 13 |
"implements", |
| 14 |
"int", |
| 15 |
"interface", |
| 16 |
"long", |
| 17 |
"native", |
| 18 |
"package", |
| 19 |
"private", |
| 20 |
"protected", |
| 21 |
"public", |
| 22 |
"short", |
| 23 |
"static", |
| 24 |
"synchronized", |
| 25 |
"throws", |
| 26 |
"transient", |
| 27 |
"volatile", |
| 28 |
]); |
| 29 |
|
| 30 |
/** |
| 31 |
* Check if the input `name` is a valid identifier name according to the ES3 specification. |
| 32 |
* |
| 33 |
* Additional ES3 reserved words are |
| 34 |
*/ |
| 35 |
export default function isValidES3Identifier(name: string): boolean { |
| 36 |
return isValidIdentifier(name) && !RESERVED_WORDS_ES3_ONLY.has(name); |
| 37 |
} |