react / wstein / node_modules / browserify / node_modules / module-deps / node_modules / detective / node_modules / escodegen / node_modules / esutils / lib / keyword.js
80621 views/*1Copyright (C) 2013 Yusuke Suzuki <[email protected]>23Redistribution and use in source and binary forms, with or without4modification, are permitted provided that the following conditions are met:56* Redistributions of source code must retain the above copyright7notice, this list of conditions and the following disclaimer.8* Redistributions in binary form must reproduce the above copyright9notice, this list of conditions and the following disclaimer in the10documentation and/or other materials provided with the distribution.1112THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"13AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY16DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES17(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;18LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND19ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF21THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.22*/2324(function () {25'use strict';2627var code = require('./code');2829function isStrictModeReservedWordES6(id) {30switch (id) {31case 'implements':32case 'interface':33case 'package':34case 'private':35case 'protected':36case 'public':37case 'static':38case 'let':39return true;40default:41return false;42}43}4445function isKeywordES5(id, strict) {46// yield should not be treated as keyword under non-strict mode.47if (!strict && id === 'yield') {48return false;49}50return isKeywordES6(id, strict);51}5253function isKeywordES6(id, strict) {54if (strict && isStrictModeReservedWordES6(id)) {55return true;56}5758switch (id.length) {59case 2:60return (id === 'if') || (id === 'in') || (id === 'do');61case 3:62return (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');63case 4:64return (id === 'this') || (id === 'else') || (id === 'case') ||65(id === 'void') || (id === 'with') || (id === 'enum');66case 5:67return (id === 'while') || (id === 'break') || (id === 'catch') ||68(id === 'throw') || (id === 'const') || (id === 'yield') ||69(id === 'class') || (id === 'super');70case 6:71return (id === 'return') || (id === 'typeof') || (id === 'delete') ||72(id === 'switch') || (id === 'export') || (id === 'import');73case 7:74return (id === 'default') || (id === 'finally') || (id === 'extends');75case 8:76return (id === 'function') || (id === 'continue') || (id === 'debugger');77case 10:78return (id === 'instanceof');79default:80return false;81}82}8384function isReservedWordES5(id, strict) {85return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);86}8788function isReservedWordES6(id, strict) {89return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);90}9192function isRestrictedWord(id) {93return id === 'eval' || id === 'arguments';94}9596function isIdentifierName(id) {97var i, iz, ch;9899if (id.length === 0) {100return false;101}102103ch = id.charCodeAt(0);104if (!code.isIdentifierStart(ch) || ch === 92) { // \ (backslash)105return false;106}107108for (i = 1, iz = id.length; i < iz; ++i) {109ch = id.charCodeAt(i);110if (!code.isIdentifierPart(ch) || ch === 92) { // \ (backslash)111return false;112}113}114return true;115}116117function isIdentifierES5(id, strict) {118return isIdentifierName(id) && !isReservedWordES5(id, strict);119}120121function isIdentifierES6(id, strict) {122return isIdentifierName(id) && !isReservedWordES6(id, strict);123}124125module.exports = {126isKeywordES5: isKeywordES5,127isKeywordES6: isKeywordES6,128isReservedWordES5: isReservedWordES5,129isReservedWordES6: isReservedWordES6,130isRestrictedWord: isRestrictedWord,131isIdentifierName: isIdentifierName,132isIdentifierES5: isIdentifierES5,133isIdentifierES6: isIdentifierES6134};135}());136/* vim: set sw=4 ts=4 et tw=80 : */137138139