Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
1
/**
2
* Copyright 2014 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
var KEYWORDS = [
18
'break', 'do', 'in', 'typeof', 'case', 'else', 'instanceof', 'var', 'catch',
19
'export', 'new', 'void', 'class', 'extends', 'return', 'while', 'const',
20
'finally', 'super', 'with', 'continue', 'for', 'switch', 'yield', 'debugger',
21
'function', 'this', 'default', 'if', 'throw', 'delete', 'import', 'try'
22
];
23
24
var FUTURE_RESERVED_WORDS = [
25
'enum', 'await', 'implements', 'package', 'protected', 'static', 'interface',
26
'private', 'public'
27
];
28
29
var LITERALS = [
30
'null',
31
'true',
32
'false'
33
];
34
35
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-reserved-words
36
var RESERVED_WORDS = [].concat(
37
KEYWORDS,
38
FUTURE_RESERVED_WORDS,
39
LITERALS
40
);
41
42
var reservedWordsMap = Object.create(null);
43
RESERVED_WORDS.forEach(function(k) {
44
reservedWordsMap[k] = true;
45
});
46
47
/**
48
* This list should not grow as new reserved words are introdued. This list is
49
* of words that need to be quoted because ES3-ish browsers do not allow their
50
* use as identifier names.
51
*/
52
var ES3_FUTURE_RESERVED_WORDS = [
53
'enum', 'implements', 'package', 'protected', 'static', 'interface',
54
'private', 'public'
55
];
56
57
var ES3_RESERVED_WORDS = [].concat(
58
KEYWORDS,
59
ES3_FUTURE_RESERVED_WORDS,
60
LITERALS
61
);
62
63
var es3ReservedWordsMap = Object.create(null);
64
ES3_RESERVED_WORDS.forEach(function(k) {
65
es3ReservedWordsMap[k] = true;
66
});
67
68
exports.isReservedWord = function(word) {
69
return !!reservedWordsMap[word];
70
};
71
72
exports.isES3ReservedWord = function(word) {
73
return !!es3ReservedWordsMap[word];
74
};
75
76