2 Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 var code = require('./code');
30 function isStrictModeReservedWordES6(id) {
46 function isKeywordES5(id, strict) {
47 // yield should not be treated as keyword under non-strict mode.
48 if (!strict && id === 'yield') {
51 return isKeywordES6(id, strict);
54 function isKeywordES6(id, strict) {
55 if (strict && isStrictModeReservedWordES6(id)) {
61 return (id === 'if') || (id === 'in') || (id === 'do');
63 return (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
65 return (id === 'this') || (id === 'else') || (id === 'case') ||
66 (id === 'void') || (id === 'with') || (id === 'enum');
68 return (id === 'while') || (id === 'break') || (id === 'catch') ||
69 (id === 'throw') || (id === 'const') || (id === 'yield') ||
70 (id === 'class') || (id === 'super');
72 return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
73 (id === 'switch') || (id === 'export') || (id === 'import');
75 return (id === 'default') || (id === 'finally') || (id === 'extends');
77 return (id === 'function') || (id === 'continue') || (id === 'debugger');
79 return (id === 'instanceof');
85 function isReservedWordES5(id, strict) {
86 return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
89 function isReservedWordES6(id, strict) {
90 return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
93 function isRestrictedWord(id) {
94 return id === 'eval' || id === 'arguments';
97 function isIdentifierName(id) {
100 if (id.length === 0) {
104 ch = id.charCodeAt(0);
105 if (!code.isIdentifierStart(ch) || ch === 92) { // \ (backslash)
109 for (i = 1, iz = id.length; i < iz; ++i) {
110 ch = id.charCodeAt(i);
111 if (!code.isIdentifierPart(ch) || ch === 92) { // \ (backslash)
118 function isIdentifierES5(id, strict) {
119 return isIdentifierName(id) && !isReservedWordES5(id, strict);
122 function isIdentifierES6(id, strict) {
123 return isIdentifierName(id) && !isReservedWordES6(id, strict);
127 isKeywordES5: isKeywordES5,
128 isKeywordES6: isKeywordES6,
129 isReservedWordES5: isReservedWordES5,
130 isReservedWordES6: isReservedWordES6,
131 isRestrictedWord: isRestrictedWord,
132 isIdentifierName: isIdentifierName,
133 isIdentifierES5: isIdentifierES5,
134 isIdentifierES6: isIdentifierES6
137 /* vim: set sw=4 ts=4 et tw=80 : */