1 line
5.2 KiB
JSON
1 line
5.2 KiB
JSON
{"ast":null,"code":"/*\n Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n * Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in the\n documentation and/or other materials provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY\n DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/\n(function () {\n 'use strict';\n\n var code = require('./code');\n\n function isStrictModeReservedWordES6(id) {\n switch (id) {\n case 'implements':\n case 'interface':\n case 'package':\n case 'private':\n case 'protected':\n case 'public':\n case 'static':\n case 'let':\n return true;\n\n default:\n return false;\n }\n }\n\n function isKeywordES5(id, strict) {\n // yield should not be treated as keyword under non-strict mode.\n if (!strict && id === 'yield') {\n return false;\n }\n\n return isKeywordES6(id, strict);\n }\n\n function isKeywordES6(id, strict) {\n if (strict && isStrictModeReservedWordES6(id)) {\n return true;\n }\n\n switch (id.length) {\n case 2:\n return id === 'if' || id === 'in' || id === 'do';\n\n case 3:\n return id === 'var' || id === 'for' || id === 'new' || id === 'try';\n\n case 4:\n return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';\n\n case 5:\n return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';\n\n case 6:\n return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';\n\n case 7:\n return id === 'default' || id === 'finally' || id === 'extends';\n\n case 8:\n return id === 'function' || id === 'continue' || id === 'debugger';\n\n case 10:\n return id === 'instanceof';\n\n default:\n return false;\n }\n }\n\n function isReservedWordES5(id, strict) {\n return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);\n }\n\n function isReservedWordES6(id, strict) {\n return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);\n }\n\n function isRestrictedWord(id) {\n return id === 'eval' || id === 'arguments';\n }\n\n function isIdentifierNameES5(id) {\n var i, iz, ch;\n\n if (id.length === 0) {\n return false;\n }\n\n ch = id.charCodeAt(0);\n\n if (!code.isIdentifierStartES5(ch)) {\n return false;\n }\n\n for (i = 1, iz = id.length; i < iz; ++i) {\n ch = id.charCodeAt(i);\n\n if (!code.isIdentifierPartES5(ch)) {\n return false;\n }\n }\n\n return true;\n }\n\n function decodeUtf16(lead, trail) {\n return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;\n }\n\n function isIdentifierNameES6(id) {\n var i, iz, ch, lowCh, check;\n\n if (id.length === 0) {\n return false;\n }\n\n check = code.isIdentifierStartES6;\n\n for (i = 0, iz = id.length; i < iz; ++i) {\n ch = id.charCodeAt(i);\n\n if (0xD800 <= ch && ch <= 0xDBFF) {\n ++i;\n\n if (i >= iz) {\n return false;\n }\n\n lowCh = id.charCodeAt(i);\n\n if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {\n return false;\n }\n\n ch = decodeUtf16(ch, lowCh);\n }\n\n if (!check(ch)) {\n return false;\n }\n\n check = code.isIdentifierPartES6;\n }\n\n return true;\n }\n\n function isIdentifierES5(id, strict) {\n return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);\n }\n\n function isIdentifierES6(id, strict) {\n return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);\n }\n\n module.exports = {\n isKeywordES5: isKeywordES5,\n isKeywordES6: isKeywordES6,\n isReservedWordES5: isReservedWordES5,\n isReservedWordES6: isReservedWordES6,\n isRestrictedWord: isRestrictedWord,\n isIdentifierNameES5: isIdentifierNameES5,\n isIdentifierNameES6: isIdentifierNameES6,\n isIdentifierES5: isIdentifierES5,\n isIdentifierES6: isIdentifierES6\n };\n})();\n/* vim: set sw=4 ts=4 et tw=80 : */","map":null,"metadata":{},"sourceType":"script"} |