This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright 2015 Alexej Yaroshevich and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+64
View File
@@ -0,0 +1,64 @@
# reserved-words
[![Build Status](https://secure.travis-ci.org/zxqfox/reserved-words.svg)](http://travis-ci.org/zxqfox/reserved-words)
## What is it?
Tiny package for detecting reserved words.
`Reserved Word` is either a `Keyword`, or a `Future Reserved Word`, or a `Null Literal`, or a `Boolean Literal`.
See: [ES5 #7.6.1](http://es5.github.io/#x7.6.1) and
[ES6 #11.6.2](http://www.ecma-international.org/ecma-262/6.0/#sec-reserved-words).
## Installation
```
npm install reserved-words
```
## API
### check(word, [dialect], [strict])
Returns `true` if provided identifier string is a Reserved Word
in some ECMAScript dialect (ECMA-262 edition).
If the `strict` flag is truthy, this function additionally checks whether
`word` is a Keyword or Future Reserved Word under strict mode.
#### Example
```
var reserved = require('reserved-words');
reserved.check('volatile', 'es3'); // true
reserved.check('volatile', 'es2015'); // false
reserved.check('yield', 3); // false
reserved.check('yield', 6); // true
```
### dialects
#### es3 (or 3)
Represents [ECMA-262 3rd edition](http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf).
See section 7.5.1.
#### es5 (or 5)
Represents [ECMA-262 5th edition (ECMAScript 5.1)](http://es5.github.io/).
Reserved Words are formally defined in ECMA262 sections
[7.6.1.1](http://es5.github.io/#x7.6.1.1) and [7.6.1.2](http://es5.github.io/#x7.6.1.2).
#### es2015 (or es6, 6)
Represents [ECMA-262 6th edition](ECMAScript 2015).
Reserved Words are formally defined in sections
[11.6.2.1](http://ecma-international.org/ecma-262/6.0/#sec-keywords) and
[11.6.2.2](http://ecma-international.org/ecma-262/6.0/#sec-future-reserved-words).
### License
Licensed under [The MIT License](https://github.com/zxqfox/reserved-words/blob/master/LICENSE)
+1
View File
@@ -0,0 +1 @@
module.exports = require('./reserved-words');
+177
View File
@@ -0,0 +1,177 @@
var assert = require('assert');
/**
* Structure for storing keywords.
*
* @typedef {Object.<String,Boolean>} KeywordsHash
*/
/**
* ECMAScript dialects.
*
* @const
* @type {Object.<String,Number|String>} - keys as readable names and values as versions
*/
var DIALECTS = {
es3: 3,
es5: 5,
es2015: 6,
es7: 7,
// aliases
es6: 6,
'default': 5,
next: 6
};
/**
* ECMAScript reserved words.
*
* @type {Object.<String,KeywordsHash>}
*/
var KEYWORDS = exports.KEYWORDS = {};
/**
* Check word for being an reserved word.
*
* @param {String} word - word to check
* @param {String|Number} [dialect] - dialect or version
* @param {Boolean} [strict] - strict mode
* @returns {?Boolean}
*/
exports.check = function check(word, dialect, strict) {
dialect = dialect || DIALECTS.default;
var version = DIALECTS[dialect] || dialect;
if (strict && version >= 5) {
version += '-strict';
}
assert(KEYWORDS[version], 'Unknown dialect');
return KEYWORDS[version].hasOwnProperty(word);
};
/**
* Reserved Words for ES3
*
* ECMA-262 3rd: 7.5.1
* http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf
*
* @type {KeywordsHash}
*/
KEYWORDS['3'] = _hash(
// Keyword, ECMA-262 3rd: 7.5.2
'break else new var',
'case finally return void',
'catch for switch while',
'continue function this with',
'default if throw',
'delete in try',
'do instanceof typeof',
// FutureReservedWord, ECMA-262 3rd 7.5.3
'abstract enum int short',
'boolean export interface static',
'byte extends long super',
'char final native synchronized',
'class float package throws',
'const goto private transient',
'debugger implements protected volatile',
'double import public',
// NullLiteral & BooleanLiteral
'null true false'
);
/**
* Reserved Words for ES5.
*
* http://es5.github.io/#x7.6.1
*
* @type {KeywordsHash}
*/
KEYWORDS['5'] = _hash(
// Keyword
'break do instanceof typeof',
'case else new var',
'catch finally return void',
'continue for switch while',
'debugger function this with',
'default if throw',
'delete in try',
// FutureReservedWord
'class enum extends super',
'const export import',
// NullLiteral & BooleanLiteral
'null true false'
);
/**
* Reserved Words for ES5 in strict mode.
*
* @type {KeywordsHash}
*/
KEYWORDS['5-strict'] = _hash(
KEYWORDS['5'],
// FutureReservedWord, strict mode. http://es5.github.io/#x7.6.1.2
'implements let private public yield',
'interface package protected static'
);
/**
* Reserved Words for ES6.
*
* 11.6.2
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-reserved-words
*
* @type {KeywordsHash}
*/
KEYWORDS['6'] = _hash(
// Keywords, ES6 11.6.2.1, http://www.ecma-international.org/ecma-262/6.0/index.html#sec-keywords
'break do in typeof',
'case else instanceof var',
'catch export new void',
'class extends return while',
'const finally super with',
'continue for switch yield',
'debugger function this',
'default if throw',
'delete import try',
// Future Reserved Words, ES6 11.6.2.2
// http://www.ecma-international.org/ecma-262/6.0/index.html#sec-future-reserved-words
'enum await',
// NullLiteral & BooleanLiteral
'null true false'
);
/**
* Reserved Words for ES6 in strict mode.
*
* @type {KeywordsHash}
*/
KEYWORDS['6-strict'] = _hash(
KEYWORDS['6'],
// Keywords, ES6 11.6.2.1
'let static',
// Future Reserved Words, ES6 11.6.2.2
'implements package protected',
'interface private public'
);
/**
* Generates hash from strings
*
* @private
* @param {...String|KeywordsHash} keywords - Space-delimited string or previous result of _hash
* @return {KeywordsHash} - Object with keywords in keys and true in values
*/
function _hash() {
var set = Array.prototype.map.call(arguments, function(v) {
return typeof v === 'string' ? v : Object.keys(v).join(' ');
}).join(' ');
return set.split(/\s+/)
.reduce(function(res, keyword) {
res[keyword] = true;
return res;
}, {});
}
+71
View File
@@ -0,0 +1,71 @@
{
"_args": [
[
"reserved-words@0.1.2",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_development": true,
"_from": "reserved-words@0.1.2",
"_id": "reserved-words@0.1.2",
"_inBundle": false,
"_integrity": "sha1-AKCUD5jNUBrqqsMWQR2a3FKzGrE=",
"_location": "/reserved-words",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "reserved-words@0.1.2",
"name": "reserved-words",
"escapedName": "reserved-words",
"rawSpec": "0.1.2",
"saveSpec": null,
"fetchSpec": "0.1.2"
},
"_requiredBy": [
"/eslint-plugin-unicorn"
],
"_resolved": "https://registry.npmjs.org/reserved-words/-/reserved-words-0.1.2.tgz",
"_spec": "0.1.2",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"author": {
"name": "Alexej Yaroshevich",
"email": "zxqfox@gmail.com",
"url": "http://github.com/zxqfox"
},
"bugs": {
"url": "https://github.com/zxqfox/reserved-words/issues"
},
"description": "ECMAScript reserved words checker",
"devDependencies": {
"jscs": "^1.13.1",
"jscs-jsdoc": "^1.1.0",
"jshint": "^2.8.0",
"mocha": "^2.2.5"
},
"files": [
"lib",
"README.md",
"LICENSE"
],
"homepage": "https://github.com/zxqfox/reserved-words#readme",
"keywords": [
"ES3",
"ES5",
"ES6",
"ReservedWord",
"Keyword",
"checker"
],
"license": "MIT",
"main": "lib/index.js",
"name": "reserved-words",
"repository": {
"type": "git",
"url": "git+https://github.com/zxqfox/reserved-words.git"
},
"scripts": {
"test": "jshint && jscs lib test && mocha"
},
"version": "0.1.2"
}