1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | (function () {
|
26 | 'use strict';
|
27 |
|
28 | var code = require('./code');
|
29 |
|
30 | function isStrictModeReservedWordES6(id) {
|
31 | switch (id) {
|
32 | case 'implements':
|
33 | case 'interface':
|
34 | case 'package':
|
35 | case 'private':
|
36 | case 'protected':
|
37 | case 'public':
|
38 | case 'static':
|
39 | case 'let':
|
40 | return true;
|
41 | default:
|
42 | return false;
|
43 | }
|
44 | }
|
45 |
|
46 | function isKeywordES5(id, strict) {
|
47 |
|
48 | if (!strict && id === 'yield') {
|
49 | return false;
|
50 | }
|
51 | return isKeywordES6(id, strict);
|
52 | }
|
53 |
|
54 | function isKeywordES6(id, strict) {
|
55 | if (strict && isStrictModeReservedWordES6(id)) {
|
56 | return true;
|
57 | }
|
58 |
|
59 | switch (id.length) {
|
60 | case 2:
|
61 | return (id === 'if') || (id === 'in') || (id === 'do');
|
62 | case 3:
|
63 | return (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
|
64 | case 4:
|
65 | return (id === 'this') || (id === 'else') || (id === 'case') ||
|
66 | (id === 'void') || (id === 'with') || (id === 'enum');
|
67 | case 5:
|
68 | return (id === 'while') || (id === 'break') || (id === 'catch') ||
|
69 | (id === 'throw') || (id === 'const') || (id === 'yield') ||
|
70 | (id === 'class') || (id === 'super');
|
71 | case 6:
|
72 | return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
|
73 | (id === 'switch') || (id === 'export') || (id === 'import');
|
74 | case 7:
|
75 | return (id === 'default') || (id === 'finally') || (id === 'extends');
|
76 | case 8:
|
77 | return (id === 'function') || (id === 'continue') || (id === 'debugger');
|
78 | case 10:
|
79 | return (id === 'instanceof');
|
80 | default:
|
81 | return false;
|
82 | }
|
83 | }
|
84 |
|
85 | function isReservedWordES5(id, strict) {
|
86 | return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
|
87 | }
|
88 |
|
89 | function isReservedWordES6(id, strict) {
|
90 | return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
|
91 | }
|
92 |
|
93 | function isRestrictedWord(id) {
|
94 | return id === 'eval' || id === 'arguments';
|
95 | }
|
96 |
|
97 | function isIdentifierName(id) {
|
98 | var i, iz, ch;
|
99 |
|
100 | if (id.length === 0) {
|
101 | return false;
|
102 | }
|
103 |
|
104 | ch = id.charCodeAt(0);
|
105 | if (!code.isIdentifierStart(ch) || ch === 92) {
|
106 | return false;
|
107 | }
|
108 |
|
109 | for (i = 1, iz = id.length; i < iz; ++i) {
|
110 | ch = id.charCodeAt(i);
|
111 | if (!code.isIdentifierPart(ch) || ch === 92) {
|
112 | return false;
|
113 | }
|
114 | }
|
115 | return true;
|
116 | }
|
117 |
|
118 | function isIdentifierES5(id, strict) {
|
119 | return isIdentifierName(id) && !isReservedWordES5(id, strict);
|
120 | }
|
121 |
|
122 | function isIdentifierES6(id, strict) {
|
123 | return isIdentifierName(id) && !isReservedWordES6(id, strict);
|
124 | }
|
125 |
|
126 | module.exports = {
|
127 | isKeywordES5: isKeywordES5,
|
128 | isKeywordES6: isKeywordES6,
|
129 | isReservedWordES5: isReservedWordES5,
|
130 | isReservedWordES6: isReservedWordES6,
|
131 | isRestrictedWord: isRestrictedWord,
|
132 | isIdentifierName: isIdentifierName,
|
133 | isIdentifierES5: isIdentifierES5,
|
134 | isIdentifierES6: isIdentifierES6
|
135 | };
|
136 | }());
|
137 |
|