diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000000000000000000000000000000000000..39903e1ad5a587da948b18e96b14a3937a2b4775 --- /dev/null +++ b/.bowerrc @@ -0,0 +1,14 @@ +{ + "directory": "public/assets/libs", + "ignoredDependencies": [ + "es6-promise", + "file-saver", + "html2canvas", + "jspdf", + "jspdf-autotable", + "pdfmake" + ], + "scripts":{ + "postinstall": "node bower-cleanup.js" + } +} diff --git a/.gitignore b/.gitignore index b209131183756f6928824b5efc4c11f27584ffd7..56bdaf6973fa702982698349fce5f4f92d4f508a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /public/assets/libs/ /public/assets/addons/* /public/uploads/* +.DS_Store .idea composer.lock *.log diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000000000000000000000000000000000000..bbcd57ba7a3e383fa344915fa60c03304424dc00 --- /dev/null +++ b/.npmrc @@ -0,0 +1,4 @@ +# 使用自定义镜像源 +registry=http://mirrors.tencent.com/npm/ +#关闭SSL验证 +strict-ssl=false \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 5fc383837b620e96d3a0d0ecc2f4c3b5179aef7a..69b14f3d9cf3d6c77fc821ee33beca1aa3016ae7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,7 +14,7 @@ module.exports = function (grunt) { compile: { options: type === 'js' ? { optimizeCss: "standard", - optimize: "none", //可使用uglify|closure|none + optimize: "uglify", //可使用uglify|closure|none preserveLicenseComments: true, removeCombined: false, baseUrl: "./public/assets/js/", //JS文件所在的基础目录 @@ -23,7 +23,7 @@ module.exports = function (grunt) { } : { optimizeCss: "default", optimize: "uglify", //可使用uglify|closure|none - cssIn: "./public/assets/css/" + module + ".css", //JS文件所在的基础目录 + cssIn: "./public/assets/css/" + module + ".css", //CSS文件所在的基础目录 out: "./public/assets/css/" + module + ".min.css" //目标文件 } } @@ -110,11 +110,25 @@ module.exports = function (grunt) { let dists = mainPackage.dists || []; let files = []; + // 兼容旧版本bower使用的目录 + let specialKey = { + 'fastadmin-bootstraptable': 'bootstrap-table', + 'sortablejs': 'Sortable', + 'tableexport.jquery.plugin': 'tableExport.jquery.plugin', + }; Object.keys(dists).forEach(key => { let src = ["**/*LICENSE*", "**/*license*"]; src = src.concat(Array.isArray(dists[key]) ? dists[key] : [dists[key]]); - files.push({expand: true, cwd: nodeModulesDir + "/" + key, src: src, dest: 'public/assets/libs/' + key + "/"}); + files.push({expand: true, cwd: nodeModulesDir + "/" + key, src: src, dest: 'public/assets/libs/' + (specialKey[key] || key) + "/"}); }); + + // 兼容bower历史路径文件 + files = [...files, + {src: nodeModulesDir + "/toastr/build/toastr.min.css", dest: "public/assets/libs/toastr/toastr.min.css"}, + {src: nodeModulesDir + "/bootstrap-slider/dist/css/bootstrap-slider.css", dest: "public/assets/libs/bootstrap-slider/slider.css"}, + {expand: true, cwd: nodeModulesDir + "/bootstrap-slider/dist", src: ["*.js"], dest: "public/assets/libs/bootstrap-slider/"} + ] + grunt.config.set('copy.main.files', files); grunt.task.run("copy:main"); }); diff --git a/README.md b/README.md index 0a0673784073aae1e0c9e99838d710d924ea98d5..9296a29221580374c8e877136bda8587fbe537cd 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,9 @@ FastAdmin是一款基于ThinkPHP+Bootstrap的极速后台开发框架。 * 多语言支持,服务端及客户端支持 * 支持大文件分片上传、剪切板粘贴上传、拖拽上传,进度条显示,图片上传前压缩 * 支持表格固定列、固定表头、跨页选择、Excel导出、模板渲染等功能 -* 强大的第三方应用模块支持([CMS](https://www.fastadmin.net/store/cms.html)、[博客](https://www.fastadmin.net/store/blog.html)、[知识付费问答](https://www.fastadmin.net/store/ask.html)、[在线投票系统](https://www.fastadmin.net/store/vote.html)、[B2C商城](https://www.fastadmin.net/store/shopro.html)、[B2B2C商城](https://www.fastadmin.net/store/wanlshop.html)) -* 支持CMS、博客、知识付费问答无缝整合[Xunsearch全文搜索](https://www.fastadmin.net/store/xunsearch.html) -* 第三方小程序支持([CMS小程序](https://www.fastadmin.net/store/cms.html)、[预订小程序](https://www.fastadmin.net/store/ball.html)、[问答小程序](https://www.fastadmin.net/store/ask.html)、[点餐小程序](https://www.fastadmin.net/store/unidrink.html)、[B2C小程序](https://www.fastadmin.net/store/shopro.html)、[B2B2C小程序](https://www.fastadmin.net/store/wanlshop.html)、[博客小程序](https://www.fastadmin.net/store/blog.html)) +* 强大的第三方应用模块支持([CMS](https://www.fastadmin.net/store/cms.html)、[CRM](https://www.fastadmin.net/store/facrm.html)、[企业网站管理系统](https://www.fastadmin.net/store/ldcms.html)、[知识库文档系统](https://www.fastadmin.net/store/knowbase.html)、[在线投票系统](https://www.fastadmin.net/store/vote.html)、[B2C商城](https://www.fastadmin.net/store/shopro.html)、[B2B2C商城](https://www.fastadmin.net/store/wanlshop.html)) * 整合第三方短信接口(阿里云、腾讯云短信) -* 无缝整合第三方云存储(七牛云、阿里云OSS、又拍云)功能,支持云储存分片上传 +* 无缝整合第三方云存储(七牛云、阿里云OSS、腾讯云存储、又拍云)功能,支持云储存分片上传 * 第三方富文本编辑器支持(Summernote、百度编辑器) * 第三方登录(QQ、微信、微博)整合 * 第三方支付(微信、支付宝)无缝整合,微信支持PC端扫码支付 @@ -57,9 +55,9 @@ https://demo.fastadmin.net 问答社区: https://ask.fastadmin.net -Github: https://github.com/karsonzhang/fastadmin +Github: https://github.com/fastadminnet/fastadmin -Gitee: https://gitee.com/karson/fastadmin +Gitee: https://gitee.com/fastadminnet/fastadmin ## 特别鸣谢 diff --git a/application/admin/command/Api.php b/application/admin/command/Api.php index caff52b4ffede64d49b9b5f657454a28a7decd1d..925cb9775da784afe87e65135f298d04f1c9939d 100644 --- a/application/admin/command/Api.php +++ b/application/admin/command/Api.php @@ -98,13 +98,19 @@ class Api extends Command foreach ($files as $name => $file) { if (!$file->isDir() && $file->getExtension() == 'php') { $filePath = $file->getRealPath(); - $classes[] = $this->getClassFromFile($filePath); + $className = $this->getClassFromFile($filePath); + if ($className) { + $classes[] = $className; + } } } } else { foreach ($controller as $index => $item) { $filePath = $moduleDir . Config::get('url_controller_layer') . DS . $item . '.php'; - $classes[] = $this->getClassFromFile($filePath); + $className = $this->getClassFromFile($filePath); + if ($className) { + $classes[] = $className; + } } } @@ -183,7 +189,7 @@ class Api extends Command } } } - - return $namespace . '\\' . $class; + $className = $namespace . '\\' . $class; + return preg_match('/([a-z0-9_\\]+)([a-z0-9_]+)$/i', $className) ? $className : ''; } } diff --git a/application/admin/command/Api/library/Builder.php b/application/admin/command/Api/library/Builder.php index 7037378b9a3f22459ca6224057b257b15b6f90a2..1b68d6cdbe0e78e29663d0e265c1fff512a27e1e 100755 --- a/application/admin/command/Api/library/Builder.php +++ b/application/admin/command/Api/library/Builder.php @@ -90,14 +90,15 @@ class Builder $typeArr = [ 'integer' => 'number', - 'file' => 'file', + 'file' => 'file', ]; $paramslist = array(); foreach ($docs['ApiParams'] as $params) { - $inputtype = $params['type'] && isset($typeArr[$params['type']]) ? $typeArr[$params['type']] : ($params['name'] == 'password' ? 'password' : 'text'); + $type = strtolower($params['type'] ?? 'string'); + $inputtype = $typeArr[$type] ?? ($params['name'] == 'password' ? 'password' : 'text'); $tr = array( 'name' => $params['name'], - 'type' => $params['type'] ?? 'string', + 'type' => $type, 'inputtype' => $inputtype, 'sample' => $params['sample'] ?? '', 'required' => $params['required'] ?? true, @@ -162,7 +163,7 @@ class Builder 'OPTIONS' => 'label-info' ); - return isset($labes[$method]) ? $labes[$method] : $labes['GET']; + return $labes[$method] ?? $labes['GET']; } public function parse() @@ -230,7 +231,7 @@ class Builder foreach ($docsList as $index => &$methods) { $methodSectorArr = []; foreach ($methods as $name => $method) { - $methodSectorArr[$name] = isset($method['weigh']) ? $method['weigh'] : 0; + $methodSectorArr[$name] = $method['weigh'] ?? 0; } arsort($methodSectorArr); $methods = array_merge(array_flip(array_keys($methodSectorArr)), $methods); @@ -253,7 +254,6 @@ class Builder public function render($template, $vars = []) { $docsList = $this->parse(); - return $this->view->display(file_get_contents($template), array_merge($vars, ['docsList' => $docsList])); } } diff --git a/application/admin/command/Api/template/index.html b/application/admin/command/Api/template/index.html index 365c929138c1b1fb0df505d4f244f77e7793002b..698e84c281ac0a39c8d37f1afe1d9a39e55ec12a 100755 --- a/application/admin/command/Api/template/index.html +++ b/application/admin/command/Api/template/index.html @@ -154,8 +154,8 @@
expect(value)
- * @since 2.0
- */
- function expectCommaSeparator() {
- var token;
-
- if (extra.errors) {
- token = lookahead;
- if (token.type === Token.Punctuator && token.value === ',') {
- lex();
- } else if (token.type === Token.Punctuator && token.value === ';') {
- lex();
- tolerateUnexpectedToken(token);
- } else {
- tolerateUnexpectedToken(token, Messages.UnexpectedToken);
- }
- } else {
- expect(',');
- }
- }
-
- // Expect the next token to match the specified keyword.
- // If not, an exception will be thrown.
-
- function expectKeyword(keyword) {
- var token = lex();
- if (token.type !== Token.Keyword || token.value !== keyword) {
- throwUnexpectedToken(token);
- }
- }
-
- // Return true if the next token matches the specified punctuator.
-
- function match(value) {
- return lookahead.type === Token.Punctuator && lookahead.value === value;
- }
-
- // Return true if the next token matches the specified keyword
-
- function matchKeyword(keyword) {
- return lookahead.type === Token.Keyword && lookahead.value === keyword;
- }
-
- // Return true if the next token matches the specified contextual keyword
- // (where an identifier is sometimes a keyword depending on the context)
-
- function matchContextualKeyword(keyword) {
- return lookahead.type === Token.Identifier && lookahead.value === keyword;
- }
-
- // Return true if the next token is an assignment operator
-
- function matchAssign() {
- var op;
-
- if (lookahead.type !== Token.Punctuator) {
- return false;
- }
- op = lookahead.value;
- return op === '=' ||
- op === '*=' ||
- op === '/=' ||
- op === '%=' ||
- op === '+=' ||
- op === '-=' ||
- op === '<<=' ||
- op === '>>=' ||
- op === '>>>=' ||
- op === '&=' ||
- op === '^=' ||
- op === '|=';
- }
-
- function consumeSemicolon() {
- // Catch the very common case first: immediately a semicolon (U+003B).
- if (source.charCodeAt(startIndex) === 0x3B || match(';')) {
- lex();
- return;
- }
-
- if (hasLineTerminator) {
- return;
- }
-
- // FIXME(ikarienator): this is seemingly an issue in the previous location info convention.
- lastIndex = startIndex;
- lastLineNumber = startLineNumber;
- lastLineStart = startLineStart;
-
- if (lookahead.type !== Token.EOF && !match('}')) {
- throwUnexpectedToken(lookahead);
- }
- }
-
- // Cover grammar support.
- //
- // When an assignment expression position starts with an left parenthesis, the determination of the type
- // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
- // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
- //
- // There are three productions that can be parsed in a parentheses pair that needs to be determined
- // after the outermost pair is closed. They are:
- //
- // 1. AssignmentExpression
- // 2. BindingElements
- // 3. AssignmentTargets
- //
- // In order to avoid exponential backtracking, we use two flags to denote if the production can be
- // binding element or assignment target.
- //
- // The three productions have the relationship:
- //
- // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
- //
- // with a single exception that CoverInitializedName when used directly in an Expression, generates
- // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
- // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
- //
- // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
- // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
- // the CoverInitializedName check is conducted.
- //
- // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
- // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
- // pattern. The CoverInitializedName check is deferred.
- function isolateCoverGrammar(parser) {
- var oldIsBindingElement = isBindingElement,
- oldIsAssignmentTarget = isAssignmentTarget,
- oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
- result;
- isBindingElement = true;
- isAssignmentTarget = true;
- firstCoverInitializedNameError = null;
- result = parser();
- if (firstCoverInitializedNameError !== null) {
- throwUnexpectedToken(firstCoverInitializedNameError);
- }
- isBindingElement = oldIsBindingElement;
- isAssignmentTarget = oldIsAssignmentTarget;
- firstCoverInitializedNameError = oldFirstCoverInitializedNameError;
- return result;
- }
-
- function inheritCoverGrammar(parser) {
- var oldIsBindingElement = isBindingElement,
- oldIsAssignmentTarget = isAssignmentTarget,
- oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
- result;
- isBindingElement = true;
- isAssignmentTarget = true;
- firstCoverInitializedNameError = null;
- result = parser();
- isBindingElement = isBindingElement && oldIsBindingElement;
- isAssignmentTarget = isAssignmentTarget && oldIsAssignmentTarget;
- firstCoverInitializedNameError = oldFirstCoverInitializedNameError || firstCoverInitializedNameError;
- return result;
- }
-
- // ECMA-262 13.3.3 Destructuring Binding Patterns
-
- function parseArrayPattern(params, kind) {
- var node = new Node(), elements = [], rest, restNode;
- expect('[');
-
- while (!match(']')) {
- if (match(',')) {
- lex();
- elements.push(null);
- } else {
- if (match('...')) {
- restNode = new Node();
- lex();
- params.push(lookahead);
- rest = parseVariableIdentifier(kind);
- elements.push(restNode.finishRestElement(rest));
- break;
- } else {
- elements.push(parsePatternWithDefault(params, kind));
- }
- if (!match(']')) {
- expect(',');
- }
- }
-
- }
-
- expect(']');
-
- return node.finishArrayPattern(elements);
- }
-
- function parsePropertyPattern(params, kind) {
- var node = new Node(), key, keyToken, computed = match('['), init;
- if (lookahead.type === Token.Identifier) {
- keyToken = lookahead;
- key = parseVariableIdentifier();
- if (match('=')) {
- params.push(keyToken);
- lex();
- init = parseAssignmentExpression();
-
- return node.finishProperty(
- 'init', key, false,
- new WrappingNode(keyToken).finishAssignmentPattern(key, init), false, true);
- } else if (!match(':')) {
- params.push(keyToken);
- return node.finishProperty('init', key, false, key, false, true);
- }
- } else {
- key = parseObjectPropertyKey();
- }
- expect(':');
- init = parsePatternWithDefault(params, kind);
- return node.finishProperty('init', key, computed, init, false, false);
- }
-
- function parseObjectPattern(params, kind) {
- var node = new Node(), properties = [];
-
- expect('{');
-
- while (!match('}')) {
- properties.push(parsePropertyPattern(params, kind));
- if (!match('}')) {
- expect(',');
- }
- }
-
- lex();
-
- return node.finishObjectPattern(properties);
- }
-
- function parsePattern(params, kind) {
- if (match('[')) {
- return parseArrayPattern(params, kind);
- } else if (match('{')) {
- return parseObjectPattern(params, kind);
- } else if (matchKeyword('let')) {
- if (kind === 'const' || kind === 'let') {
- tolerateUnexpectedToken(lookahead, Messages.UnexpectedToken);
- }
- }
-
- params.push(lookahead);
- return parseVariableIdentifier(kind);
- }
-
- function parsePatternWithDefault(params, kind) {
- var startToken = lookahead, pattern, previousAllowYield, right;
- pattern = parsePattern(params, kind);
- if (match('=')) {
- lex();
- previousAllowYield = state.allowYield;
- state.allowYield = true;
- right = isolateCoverGrammar(parseAssignmentExpression);
- state.allowYield = previousAllowYield;
- pattern = new WrappingNode(startToken).finishAssignmentPattern(pattern, right);
- }
- return pattern;
- }
-
- // ECMA-262 12.2.5 Array Initializer
-
- function parseArrayInitializer() {
- var elements = [], node = new Node(), restSpread;
-
- expect('[');
-
- while (!match(']')) {
- if (match(',')) {
- lex();
- elements.push(null);
- } else if (match('...')) {
- restSpread = new Node();
- lex();
- restSpread.finishSpreadElement(inheritCoverGrammar(parseAssignmentExpression));
-
- if (!match(']')) {
- isAssignmentTarget = isBindingElement = false;
- expect(',');
- }
- elements.push(restSpread);
- } else {
- elements.push(inheritCoverGrammar(parseAssignmentExpression));
-
- if (!match(']')) {
- expect(',');
- }
- }
- }
-
- lex();
-
- return node.finishArrayExpression(elements);
- }
-
- // ECMA-262 12.2.6 Object Initializer
-
- function parsePropertyFunction(node, paramInfo, isGenerator) {
- var previousStrict, body;
-
- isAssignmentTarget = isBindingElement = false;
-
- previousStrict = strict;
- body = isolateCoverGrammar(parseFunctionSourceElements);
-
- if (strict && paramInfo.firstRestricted) {
- tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);
- }
- if (strict && paramInfo.stricted) {
- tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);
- }
-
- strict = previousStrict;
- return node.finishFunctionExpression(null, paramInfo.params, paramInfo.defaults, body, isGenerator);
- }
-
- function parsePropertyMethodFunction() {
- var params, method, node = new Node(),
- previousAllowYield = state.allowYield;
-
- state.allowYield = false;
- params = parseParams();
- state.allowYield = previousAllowYield;
-
- state.allowYield = false;
- method = parsePropertyFunction(node, params, false);
- state.allowYield = previousAllowYield;
-
- return method;
- }
-
- function parseObjectPropertyKey() {
- var token, node = new Node(), expr;
-
- token = lex();
-
- // Note: This function is called only from parseObjectProperty(), where
- // EOF and Punctuator tokens are already filtered out.
-
- switch (token.type) {
- case Token.StringLiteral:
- case Token.NumericLiteral:
- if (strict && token.octal) {
- tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);
- }
- return node.finishLiteral(token);
- case Token.Identifier:
- case Token.BooleanLiteral:
- case Token.NullLiteral:
- case Token.Keyword:
- return node.finishIdentifier(token.value);
- case Token.Punctuator:
- if (token.value === '[') {
- expr = isolateCoverGrammar(parseAssignmentExpression);
- expect(']');
- return expr;
- }
- break;
- }
- throwUnexpectedToken(token);
- }
-
- function lookaheadPropertyName() {
- switch (lookahead.type) {
- case Token.Identifier:
- case Token.StringLiteral:
- case Token.BooleanLiteral:
- case Token.NullLiteral:
- case Token.NumericLiteral:
- case Token.Keyword:
- return true;
- case Token.Punctuator:
- return lookahead.value === '[';
- }
- return false;
- }
-
- // This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals,
- // it might be called at a position where there is in fact a short hand identifier pattern or a data property.
- // This can only be determined after we consumed up to the left parentheses.
- //
- // In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller
- // is responsible to visit other options.
- function tryParseMethodDefinition(token, key, computed, node) {
- var value, options, methodNode, params,
- previousAllowYield = state.allowYield;
-
- if (token.type === Token.Identifier) {
- // check for `get` and `set`;
-
- if (token.value === 'get' && lookaheadPropertyName()) {
- computed = match('[');
- key = parseObjectPropertyKey();
- methodNode = new Node();
- expect('(');
- expect(')');
-
- state.allowYield = false;
- value = parsePropertyFunction(methodNode, {
- params: [],
- defaults: [],
- stricted: null,
- firstRestricted: null,
- message: null
- }, false);
- state.allowYield = previousAllowYield;
-
- return node.finishProperty('get', key, computed, value, false, false);
- } else if (token.value === 'set' && lookaheadPropertyName()) {
- computed = match('[');
- key = parseObjectPropertyKey();
- methodNode = new Node();
- expect('(');
-
- options = {
- params: [],
- defaultCount: 0,
- defaults: [],
- firstRestricted: null,
- paramSet: {}
- };
- if (match(')')) {
- tolerateUnexpectedToken(lookahead);
- } else {
- state.allowYield = false;
- parseParam(options);
- state.allowYield = previousAllowYield;
- if (options.defaultCount === 0) {
- options.defaults = [];
- }
- }
- expect(')');
-
- state.allowYield = false;
- value = parsePropertyFunction(methodNode, options, false);
- state.allowYield = previousAllowYield;
-
- return node.finishProperty('set', key, computed, value, false, false);
- }
- } else if (token.type === Token.Punctuator && token.value === '*' && lookaheadPropertyName()) {
- computed = match('[');
- key = parseObjectPropertyKey();
- methodNode = new Node();
-
- state.allowYield = true;
- params = parseParams();
- state.allowYield = previousAllowYield;
-
- state.allowYield = false;
- value = parsePropertyFunction(methodNode, params, true);
- state.allowYield = previousAllowYield;
-
- return node.finishProperty('init', key, computed, value, true, false);
- }
-
- if (key && match('(')) {
- value = parsePropertyMethodFunction();
- return node.finishProperty('init', key, computed, value, true, false);
- }
-
- // Not a MethodDefinition.
- return null;
- }
-
- function parseObjectProperty(hasProto) {
- var token = lookahead, node = new Node(), computed, key, maybeMethod, proto, value;
-
- computed = match('[');
- if (match('*')) {
- lex();
- } else {
- key = parseObjectPropertyKey();
- }
- maybeMethod = tryParseMethodDefinition(token, key, computed, node);
- if (maybeMethod) {
- return maybeMethod;
- }
-
- if (!key) {
- throwUnexpectedToken(lookahead);
- }
-
- // Check for duplicated __proto__
- if (!computed) {
- proto = (key.type === Syntax.Identifier && key.name === '__proto__') ||
- (key.type === Syntax.Literal && key.value === '__proto__');
- if (hasProto.value && proto) {
- tolerateError(Messages.DuplicateProtoProperty);
- }
- hasProto.value |= proto;
- }
-
- if (match(':')) {
- lex();
- value = inheritCoverGrammar(parseAssignmentExpression);
- return node.finishProperty('init', key, computed, value, false, false);
- }
-
- if (token.type === Token.Identifier) {
- if (match('=')) {
- firstCoverInitializedNameError = lookahead;
- lex();
- value = isolateCoverGrammar(parseAssignmentExpression);
- return node.finishProperty('init', key, computed,
- new WrappingNode(token).finishAssignmentPattern(key, value), false, true);
- }
- return node.finishProperty('init', key, computed, key, false, true);
- }
-
- throwUnexpectedToken(lookahead);
- }
-
- function parseObjectInitializer() {
- var properties = [], hasProto = {value: false}, node = new Node();
-
- expect('{');
-
- while (!match('}')) {
- properties.push(parseObjectProperty(hasProto));
-
- if (!match('}')) {
- expectCommaSeparator();
- }
- }
-
- expect('}');
-
- return node.finishObjectExpression(properties);
- }
-
- function reinterpretExpressionAsPattern(expr) {
- var i;
- switch (expr.type) {
- case Syntax.Identifier:
- case Syntax.MemberExpression:
- case Syntax.RestElement:
- case Syntax.AssignmentPattern:
- break;
- case Syntax.SpreadElement:
- expr.type = Syntax.RestElement;
- reinterpretExpressionAsPattern(expr.argument);
- break;
- case Syntax.ArrayExpression:
- expr.type = Syntax.ArrayPattern;
- for (i = 0; i < expr.elements.length; i++) {
- if (expr.elements[i] !== null) {
- reinterpretExpressionAsPattern(expr.elements[i]);
- }
- }
- break;
- case Syntax.ObjectExpression:
- expr.type = Syntax.ObjectPattern;
- for (i = 0; i < expr.properties.length; i++) {
- reinterpretExpressionAsPattern(expr.properties[i].value);
- }
- break;
- case Syntax.AssignmentExpression:
- expr.type = Syntax.AssignmentPattern;
- reinterpretExpressionAsPattern(expr.left);
- break;
- default:
- // Allow other node type for tolerant parsing.
- break;
- }
- }
-
- // ECMA-262 12.2.9 Template Literals
-
- function parseTemplateElement(option) {
- var node, token;
-
- if (lookahead.type !== Token.Template || (option.head && !lookahead.head)) {
- throwUnexpectedToken();
- }
-
- node = new Node();
- token = lex();
-
- return node.finishTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail);
- }
-
- function parseTemplateLiteral() {
- var quasi, quasis, expressions, node = new Node();
-
- quasi = parseTemplateElement({ head: true });
- quasis = [quasi];
- expressions = [];
-
- while (!quasi.tail) {
- expressions.push(parseExpression());
- quasi = parseTemplateElement({ head: false });
- quasis.push(quasi);
- }
-
- return node.finishTemplateLiteral(quasis, expressions);
- }
-
- // ECMA-262 12.2.10 The Grouping Operator
-
- function parseGroupExpression() {
- var expr, expressions, startToken, i, params = [];
-
- expect('(');
-
- if (match(')')) {
- lex();
- if (!match('=>')) {
- expect('=>');
- }
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: [],
- rawParams: []
- };
- }
-
- startToken = lookahead;
- if (match('...')) {
- expr = parseRestElement(params);
- expect(')');
- if (!match('=>')) {
- expect('=>');
- }
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: [expr]
- };
- }
-
- isBindingElement = true;
- expr = inheritCoverGrammar(parseAssignmentExpression);
-
- if (match(',')) {
- isAssignmentTarget = false;
- expressions = [expr];
-
- while (startIndex < length) {
- if (!match(',')) {
- break;
- }
- lex();
-
- if (match('...')) {
- if (!isBindingElement) {
- throwUnexpectedToken(lookahead);
- }
- expressions.push(parseRestElement(params));
- expect(')');
- if (!match('=>')) {
- expect('=>');
- }
- isBindingElement = false;
- for (i = 0; i < expressions.length; i++) {
- reinterpretExpressionAsPattern(expressions[i]);
- }
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: expressions
- };
- }
-
- expressions.push(inheritCoverGrammar(parseAssignmentExpression));
- }
-
- expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
- }
-
-
- expect(')');
-
- if (match('=>')) {
- if (expr.type === Syntax.Identifier && expr.name === 'yield') {
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: [expr]
- };
- }
-
- if (!isBindingElement) {
- throwUnexpectedToken(lookahead);
- }
-
- if (expr.type === Syntax.SequenceExpression) {
- for (i = 0; i < expr.expressions.length; i++) {
- reinterpretExpressionAsPattern(expr.expressions[i]);
- }
- } else {
- reinterpretExpressionAsPattern(expr);
- }
-
- expr = {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: expr.type === Syntax.SequenceExpression ? expr.expressions : [expr]
- };
- }
- isBindingElement = false;
- return expr;
- }
-
-
- // ECMA-262 12.2 Primary Expressions
-
- function parsePrimaryExpression() {
- var type, token, expr, node;
-
- if (match('(')) {
- isBindingElement = false;
- return inheritCoverGrammar(parseGroupExpression);
- }
-
- if (match('[')) {
- return inheritCoverGrammar(parseArrayInitializer);
- }
-
- if (match('{')) {
- return inheritCoverGrammar(parseObjectInitializer);
- }
-
- type = lookahead.type;
- node = new Node();
-
- if (type === Token.Identifier) {
- if (state.sourceType === 'module' && lookahead.value === 'await') {
- tolerateUnexpectedToken(lookahead);
- }
- expr = node.finishIdentifier(lex().value);
- } else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
- isAssignmentTarget = isBindingElement = false;
- if (strict && lookahead.octal) {
- tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);
- }
- expr = node.finishLiteral(lex());
- } else if (type === Token.Keyword) {
- if (!strict && state.allowYield && matchKeyword('yield')) {
- return parseNonComputedProperty();
- }
- if (!strict && matchKeyword('let')) {
- return node.finishIdentifier(lex().value);
- }
- isAssignmentTarget = isBindingElement = false;
- if (matchKeyword('function')) {
- return parseFunctionExpression();
- }
- if (matchKeyword('this')) {
- lex();
- return node.finishThisExpression();
- }
- if (matchKeyword('class')) {
- return parseClassExpression();
- }
- throwUnexpectedToken(lex());
- } else if (type === Token.BooleanLiteral) {
- isAssignmentTarget = isBindingElement = false;
- token = lex();
- token.value = (token.value === 'true');
- expr = node.finishLiteral(token);
- } else if (type === Token.NullLiteral) {
- isAssignmentTarget = isBindingElement = false;
- token = lex();
- token.value = null;
- expr = node.finishLiteral(token);
- } else if (match('/') || match('/=')) {
- isAssignmentTarget = isBindingElement = false;
- index = startIndex;
-
- if (typeof extra.tokens !== 'undefined') {
- token = collectRegex();
- } else {
- token = scanRegExp();
- }
- lex();
- expr = node.finishLiteral(token);
- } else if (type === Token.Template) {
- expr = parseTemplateLiteral();
- } else {
- throwUnexpectedToken(lex());
- }
-
- return expr;
- }
-
- // ECMA-262 12.3 Left-Hand-Side Expressions
-
- function parseArguments() {
- var args = [], expr;
-
- expect('(');
-
- if (!match(')')) {
- while (startIndex < length) {
- if (match('...')) {
- expr = new Node();
- lex();
- expr.finishSpreadElement(isolateCoverGrammar(parseAssignmentExpression));
- } else {
- expr = isolateCoverGrammar(parseAssignmentExpression);
- }
- args.push(expr);
- if (match(')')) {
- break;
- }
- expectCommaSeparator();
- }
- }
-
- expect(')');
-
- return args;
- }
-
- function parseNonComputedProperty() {
- var token, node = new Node();
-
- token = lex();
-
- if (!isIdentifierName(token)) {
- throwUnexpectedToken(token);
- }
-
- return node.finishIdentifier(token.value);
- }
-
- function parseNonComputedMember() {
- expect('.');
-
- return parseNonComputedProperty();
- }
-
- function parseComputedMember() {
- var expr;
-
- expect('[');
-
- expr = isolateCoverGrammar(parseExpression);
-
- expect(']');
-
- return expr;
- }
-
- // ECMA-262 12.3.3 The new Operator
-
- function parseNewExpression() {
- var callee, args, node = new Node();
-
- expectKeyword('new');
-
- if (match('.')) {
- lex();
- if (lookahead.type === Token.Identifier && lookahead.value === 'target') {
- if (state.inFunctionBody) {
- lex();
- return node.finishMetaProperty('new', 'target');
- }
- }
- throwUnexpectedToken(lookahead);
- }
-
- callee = isolateCoverGrammar(parseLeftHandSideExpression);
- args = match('(') ? parseArguments() : [];
-
- isAssignmentTarget = isBindingElement = false;
-
- return node.finishNewExpression(callee, args);
- }
-
- // ECMA-262 12.3.4 Function Calls
-
- function parseLeftHandSideExpressionAllowCall() {
- var quasi, expr, args, property, startToken, previousAllowIn = state.allowIn;
-
- startToken = lookahead;
- state.allowIn = true;
-
- if (matchKeyword('super') && state.inFunctionBody) {
- expr = new Node();
- lex();
- expr = expr.finishSuper();
- if (!match('(') && !match('.') && !match('[')) {
- throwUnexpectedToken(lookahead);
- }
- } else {
- expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
- }
-
- for (;;) {
- if (match('.')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseNonComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
- } else if (match('(')) {
- isBindingElement = false;
- isAssignmentTarget = false;
- args = parseArguments();
- expr = new WrappingNode(startToken).finishCallExpression(expr, args);
- } else if (match('[')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
- } else if (lookahead.type === Token.Template && lookahead.head) {
- quasi = parseTemplateLiteral();
- expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
- } else {
- break;
- }
- }
- state.allowIn = previousAllowIn;
-
- return expr;
- }
-
- // ECMA-262 12.3 Left-Hand-Side Expressions
-
- function parseLeftHandSideExpression() {
- var quasi, expr, property, startToken;
- assert(state.allowIn, 'callee of new expression always allow in keyword.');
-
- startToken = lookahead;
-
- if (matchKeyword('super') && state.inFunctionBody) {
- expr = new Node();
- lex();
- expr = expr.finishSuper();
- if (!match('[') && !match('.')) {
- throwUnexpectedToken(lookahead);
- }
- } else {
- expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
- }
-
- for (;;) {
- if (match('[')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
- } else if (match('.')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseNonComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
- } else if (lookahead.type === Token.Template && lookahead.head) {
- quasi = parseTemplateLiteral();
- expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
- } else {
- break;
- }
- }
- return expr;
- }
-
- // ECMA-262 12.4 Postfix Expressions
-
- function parsePostfixExpression() {
- var expr, token, startToken = lookahead;
-
- expr = inheritCoverGrammar(parseLeftHandSideExpressionAllowCall);
-
- if (!hasLineTerminator && lookahead.type === Token.Punctuator) {
- if (match('++') || match('--')) {
- // ECMA-262 11.3.1, 11.3.2
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
- tolerateError(Messages.StrictLHSPostfix);
- }
-
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInAssignment);
- }
-
- isAssignmentTarget = isBindingElement = false;
-
- token = lex();
- expr = new WrappingNode(startToken).finishPostfixExpression(token.value, expr);
- }
- }
-
- return expr;
- }
-
- // ECMA-262 12.5 Unary Operators
-
- function parseUnaryExpression() {
- var token, expr, startToken;
-
- if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
- expr = parsePostfixExpression();
- } else if (match('++') || match('--')) {
- startToken = lookahead;
- token = lex();
- expr = inheritCoverGrammar(parseUnaryExpression);
- // ECMA-262 11.4.4, 11.4.5
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
- tolerateError(Messages.StrictLHSPrefix);
- }
-
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInAssignment);
- }
- expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
- isAssignmentTarget = isBindingElement = false;
- } else if (match('+') || match('-') || match('~') || match('!')) {
- startToken = lookahead;
- token = lex();
- expr = inheritCoverGrammar(parseUnaryExpression);
- expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
- isAssignmentTarget = isBindingElement = false;
- } else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
- startToken = lookahead;
- token = lex();
- expr = inheritCoverGrammar(parseUnaryExpression);
- expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
- if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
- tolerateError(Messages.StrictDelete);
- }
- isAssignmentTarget = isBindingElement = false;
- } else {
- expr = parsePostfixExpression();
- }
-
- return expr;
- }
-
- function binaryPrecedence(token, allowIn) {
- var prec = 0;
-
- if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
- return 0;
- }
-
- switch (token.value) {
- case '||':
- prec = 1;
- break;
-
- case '&&':
- prec = 2;
- break;
-
- case '|':
- prec = 3;
- break;
-
- case '^':
- prec = 4;
- break;
-
- case '&':
- prec = 5;
- break;
-
- case '==':
- case '!=':
- case '===':
- case '!==':
- prec = 6;
- break;
-
- case '<':
- case '>':
- case '<=':
- case '>=':
- case 'instanceof':
- prec = 7;
- break;
-
- case 'in':
- prec = allowIn ? 7 : 0;
- break;
-
- case '<<':
- case '>>':
- case '>>>':
- prec = 8;
- break;
-
- case '+':
- case '-':
- prec = 9;
- break;
-
- case '*':
- case '/':
- case '%':
- prec = 11;
- break;
-
- default:
- break;
- }
-
- return prec;
- }
-
- // ECMA-262 12.6 Multiplicative Operators
- // ECMA-262 12.7 Additive Operators
- // ECMA-262 12.8 Bitwise Shift Operators
- // ECMA-262 12.9 Relational Operators
- // ECMA-262 12.10 Equality Operators
- // ECMA-262 12.11 Binary Bitwise Operators
- // ECMA-262 12.12 Binary Logical Operators
-
- function parseBinaryExpression() {
- var marker, markers, expr, token, prec, stack, right, operator, left, i;
-
- marker = lookahead;
- left = inheritCoverGrammar(parseUnaryExpression);
-
- token = lookahead;
- prec = binaryPrecedence(token, state.allowIn);
- if (prec === 0) {
- return left;
- }
- isAssignmentTarget = isBindingElement = false;
- token.prec = prec;
- lex();
-
- markers = [marker, lookahead];
- right = isolateCoverGrammar(parseUnaryExpression);
-
- stack = [left, token, right];
-
- while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {
-
- // Reduce: make a binary expression from the three topmost entries.
- while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
- right = stack.pop();
- operator = stack.pop().value;
- left = stack.pop();
- markers.pop();
- expr = new WrappingNode(markers[markers.length - 1]).finishBinaryExpression(operator, left, right);
- stack.push(expr);
- }
-
- // Shift.
- token = lex();
- token.prec = prec;
- stack.push(token);
- markers.push(lookahead);
- expr = isolateCoverGrammar(parseUnaryExpression);
- stack.push(expr);
- }
-
- // Final reduce to clean-up the stack.
- i = stack.length - 1;
- expr = stack[i];
- markers.pop();
- while (i > 1) {
- expr = new WrappingNode(markers.pop()).finishBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
- i -= 2;
- }
-
- return expr;
- }
-
-
- // ECMA-262 12.13 Conditional Operator
-
- function parseConditionalExpression() {
- var expr, previousAllowIn, consequent, alternate, startToken;
-
- startToken = lookahead;
-
- expr = inheritCoverGrammar(parseBinaryExpression);
- if (match('?')) {
- lex();
- previousAllowIn = state.allowIn;
- state.allowIn = true;
- consequent = isolateCoverGrammar(parseAssignmentExpression);
- state.allowIn = previousAllowIn;
- expect(':');
- alternate = isolateCoverGrammar(parseAssignmentExpression);
-
- expr = new WrappingNode(startToken).finishConditionalExpression(expr, consequent, alternate);
- isAssignmentTarget = isBindingElement = false;
- }
-
- return expr;
- }
-
- // ECMA-262 14.2 Arrow Function Definitions
-
- function parseConciseBody() {
- if (match('{')) {
- return parseFunctionSourceElements();
- }
- return isolateCoverGrammar(parseAssignmentExpression);
- }
-
- function checkPatternParam(options, param) {
- var i;
- switch (param.type) {
- case Syntax.Identifier:
- validateParam(options, param, param.name);
- break;
- case Syntax.RestElement:
- checkPatternParam(options, param.argument);
- break;
- case Syntax.AssignmentPattern:
- checkPatternParam(options, param.left);
- break;
- case Syntax.ArrayPattern:
- for (i = 0; i < param.elements.length; i++) {
- if (param.elements[i] !== null) {
- checkPatternParam(options, param.elements[i]);
- }
- }
- break;
- case Syntax.YieldExpression:
- break;
- default:
- assert(param.type === Syntax.ObjectPattern, 'Invalid type');
- for (i = 0; i < param.properties.length; i++) {
- checkPatternParam(options, param.properties[i].value);
- }
- break;
- }
- }
- function reinterpretAsCoverFormalsList(expr) {
- var i, len, param, params, defaults, defaultCount, options, token;
-
- defaults = [];
- defaultCount = 0;
- params = [expr];
-
- switch (expr.type) {
- case Syntax.Identifier:
- break;
- case PlaceHolders.ArrowParameterPlaceHolder:
- params = expr.params;
- break;
- default:
- return null;
- }
-
- options = {
- paramSet: {}
- };
-
- for (i = 0, len = params.length; i < len; i += 1) {
- param = params[i];
- switch (param.type) {
- case Syntax.AssignmentPattern:
- params[i] = param.left;
- if (param.right.type === Syntax.YieldExpression) {
- if (param.right.argument) {
- throwUnexpectedToken(lookahead);
- }
- param.right.type = Syntax.Identifier;
- param.right.name = 'yield';
- delete param.right.argument;
- delete param.right.delegate;
- }
- defaults.push(param.right);
- ++defaultCount;
- checkPatternParam(options, param.left);
- break;
- default:
- checkPatternParam(options, param);
- params[i] = param;
- defaults.push(null);
- break;
- }
- }
-
- if (strict || !state.allowYield) {
- for (i = 0, len = params.length; i < len; i += 1) {
- param = params[i];
- if (param.type === Syntax.YieldExpression) {
- throwUnexpectedToken(lookahead);
- }
- }
- }
-
- if (options.message === Messages.StrictParamDupe) {
- token = strict ? options.stricted : options.firstRestricted;
- throwUnexpectedToken(token, options.message);
- }
-
- if (defaultCount === 0) {
- defaults = [];
- }
-
- return {
- params: params,
- defaults: defaults,
- stricted: options.stricted,
- firstRestricted: options.firstRestricted,
- message: options.message
- };
- }
-
- function parseArrowFunctionExpression(options, node) {
- var previousStrict, previousAllowYield, body;
-
- if (hasLineTerminator) {
- tolerateUnexpectedToken(lookahead);
- }
- expect('=>');
-
- previousStrict = strict;
- previousAllowYield = state.allowYield;
- state.allowYield = true;
-
- body = parseConciseBody();
-
- if (strict && options.firstRestricted) {
- throwUnexpectedToken(options.firstRestricted, options.message);
- }
- if (strict && options.stricted) {
- tolerateUnexpectedToken(options.stricted, options.message);
- }
-
- strict = previousStrict;
- state.allowYield = previousAllowYield;
-
- return node.finishArrowFunctionExpression(options.params, options.defaults, body, body.type !== Syntax.BlockStatement);
- }
-
- // ECMA-262 14.4 Yield expression
-
- function parseYieldExpression() {
- var argument, expr, delegate, previousAllowYield;
-
- argument = null;
- expr = new Node();
- delegate = false;
-
- expectKeyword('yield');
-
- if (!hasLineTerminator) {
- previousAllowYield = state.allowYield;
- state.allowYield = false;
- delegate = match('*');
- if (delegate) {
- lex();
- argument = parseAssignmentExpression();
- } else {
- if (!match(';') && !match('}') && !match(')') && lookahead.type !== Token.EOF) {
- argument = parseAssignmentExpression();
- }
- }
- state.allowYield = previousAllowYield;
- }
-
- return expr.finishYieldExpression(argument, delegate);
- }
-
- // ECMA-262 12.14 Assignment Operators
-
- function parseAssignmentExpression() {
- var token, expr, right, list, startToken;
-
- startToken = lookahead;
- token = lookahead;
-
- if (!state.allowYield && matchKeyword('yield')) {
- return parseYieldExpression();
- }
-
- expr = parseConditionalExpression();
-
- if (expr.type === PlaceHolders.ArrowParameterPlaceHolder || match('=>')) {
- isAssignmentTarget = isBindingElement = false;
- list = reinterpretAsCoverFormalsList(expr);
-
- if (list) {
- firstCoverInitializedNameError = null;
- return parseArrowFunctionExpression(list, new WrappingNode(startToken));
- }
-
- return expr;
- }
-
- if (matchAssign()) {
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInAssignment);
- }
-
- // ECMA-262 12.1.1
- if (strict && expr.type === Syntax.Identifier) {
- if (isRestrictedWord(expr.name)) {
- tolerateUnexpectedToken(token, Messages.StrictLHSAssignment);
- }
- if (isStrictModeReservedWord(expr.name)) {
- tolerateUnexpectedToken(token, Messages.StrictReservedWord);
- }
- }
-
- if (!match('=')) {
- isAssignmentTarget = isBindingElement = false;
- } else {
- reinterpretExpressionAsPattern(expr);
- }
-
- token = lex();
- right = isolateCoverGrammar(parseAssignmentExpression);
- expr = new WrappingNode(startToken).finishAssignmentExpression(token.value, expr, right);
- firstCoverInitializedNameError = null;
- }
-
- return expr;
- }
-
- // ECMA-262 12.15 Comma Operator
-
- function parseExpression() {
- var expr, startToken = lookahead, expressions;
-
- expr = isolateCoverGrammar(parseAssignmentExpression);
-
- if (match(',')) {
- expressions = [expr];
-
- while (startIndex < length) {
- if (!match(',')) {
- break;
- }
- lex();
- expressions.push(isolateCoverGrammar(parseAssignmentExpression));
- }
-
- expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
- }
-
- return expr;
- }
-
- // ECMA-262 13.2 Block
-
- function parseStatementListItem() {
- if (lookahead.type === Token.Keyword) {
- switch (lookahead.value) {
- case 'export':
- if (state.sourceType !== 'module') {
- tolerateUnexpectedToken(lookahead, Messages.IllegalExportDeclaration);
- }
- return parseExportDeclaration();
- case 'import':
- if (state.sourceType !== 'module') {
- tolerateUnexpectedToken(lookahead, Messages.IllegalImportDeclaration);
- }
- return parseImportDeclaration();
- case 'const':
- return parseLexicalDeclaration({inFor: false});
- case 'function':
- return parseFunctionDeclaration(new Node());
- case 'class':
- return parseClassDeclaration();
- }
- }
-
- if (matchKeyword('let') && isLexicalDeclaration()) {
- return parseLexicalDeclaration({inFor: false});
- }
-
- return parseStatement();
- }
-
- function parseStatementList() {
- var list = [];
- while (startIndex < length) {
- if (match('}')) {
- break;
- }
- list.push(parseStatementListItem());
- }
-
- return list;
- }
-
- function parseBlock() {
- var block, node = new Node();
-
- expect('{');
-
- block = parseStatementList();
-
- expect('}');
-
- return node.finishBlockStatement(block);
- }
-
- // ECMA-262 13.3.2 Variable Statement
-
- function parseVariableIdentifier(kind) {
- var token, node = new Node();
-
- token = lex();
-
- if (token.type === Token.Keyword && token.value === 'yield') {
- if (strict) {
- tolerateUnexpectedToken(token, Messages.StrictReservedWord);
- } if (!state.allowYield) {
- throwUnexpectedToken(token);
- }
- } else if (token.type !== Token.Identifier) {
- if (strict && token.type === Token.Keyword && isStrictModeReservedWord(token.value)) {
- tolerateUnexpectedToken(token, Messages.StrictReservedWord);
- } else {
- if (strict || token.value !== 'let' || kind !== 'var') {
- throwUnexpectedToken(token);
- }
- }
- } else if (state.sourceType === 'module' && token.type === Token.Identifier && token.value === 'await') {
- tolerateUnexpectedToken(token);
- }
-
- return node.finishIdentifier(token.value);
- }
-
- function parseVariableDeclaration(options) {
- var init = null, id, node = new Node(), params = [];
-
- id = parsePattern(params, 'var');
-
- // ECMA-262 12.2.1
- if (strict && isRestrictedWord(id.name)) {
- tolerateError(Messages.StrictVarName);
- }
-
- if (match('=')) {
- lex();
- init = isolateCoverGrammar(parseAssignmentExpression);
- } else if (id.type !== Syntax.Identifier && !options.inFor) {
- expect('=');
- }
-
- return node.finishVariableDeclarator(id, init);
- }
-
- function parseVariableDeclarationList(options) {
- var opt, list;
-
- opt = { inFor: options.inFor };
- list = [parseVariableDeclaration(opt)];
-
- while (match(',')) {
- lex();
- list.push(parseVariableDeclaration(opt));
- }
-
- return list;
- }
-
- function parseVariableStatement(node) {
- var declarations;
-
- expectKeyword('var');
-
- declarations = parseVariableDeclarationList({ inFor: false });
-
- consumeSemicolon();
-
- return node.finishVariableDeclaration(declarations);
- }
-
- // ECMA-262 13.3.1 Let and Const Declarations
-
- function parseLexicalBinding(kind, options) {
- var init = null, id, node = new Node(), params = [];
-
- id = parsePattern(params, kind);
-
- // ECMA-262 12.2.1
- if (strict && id.type === Syntax.Identifier && isRestrictedWord(id.name)) {
- tolerateError(Messages.StrictVarName);
- }
-
- if (kind === 'const') {
- if (!matchKeyword('in') && !matchContextualKeyword('of')) {
- expect('=');
- init = isolateCoverGrammar(parseAssignmentExpression);
- }
- } else if ((!options.inFor && id.type !== Syntax.Identifier) || match('=')) {
- expect('=');
- init = isolateCoverGrammar(parseAssignmentExpression);
- }
-
- return node.finishVariableDeclarator(id, init);
- }
-
- function parseBindingList(kind, options) {
- var list = [parseLexicalBinding(kind, options)];
-
- while (match(',')) {
- lex();
- list.push(parseLexicalBinding(kind, options));
- }
-
- return list;
- }
-
-
- function tokenizerState() {
- return {
- index: index,
- lineNumber: lineNumber,
- lineStart: lineStart,
- hasLineTerminator: hasLineTerminator,
- lastIndex: lastIndex,
- lastLineNumber: lastLineNumber,
- lastLineStart: lastLineStart,
- startIndex: startIndex,
- startLineNumber: startLineNumber,
- startLineStart: startLineStart,
- lookahead: lookahead,
- tokenCount: extra.tokens ? extra.tokens.length : 0
- };
- }
-
- function resetTokenizerState(ts) {
- index = ts.index;
- lineNumber = ts.lineNumber;
- lineStart = ts.lineStart;
- hasLineTerminator = ts.hasLineTerminator;
- lastIndex = ts.lastIndex;
- lastLineNumber = ts.lastLineNumber;
- lastLineStart = ts.lastLineStart;
- startIndex = ts.startIndex;
- startLineNumber = ts.startLineNumber;
- startLineStart = ts.startLineStart;
- lookahead = ts.lookahead;
- if (extra.tokens) {
- extra.tokens.splice(ts.tokenCount, extra.tokens.length);
- }
- }
-
- function isLexicalDeclaration() {
- var lexical, ts;
-
- ts = tokenizerState();
-
- lex();
- lexical = (lookahead.type === Token.Identifier) || match('[') || match('{') ||
- matchKeyword('let') || matchKeyword('yield');
-
- resetTokenizerState(ts);
-
- return lexical;
- }
-
- function parseLexicalDeclaration(options) {
- var kind, declarations, node = new Node();
-
- kind = lex().value;
- assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
-
- declarations = parseBindingList(kind, options);
-
- consumeSemicolon();
-
- return node.finishLexicalDeclaration(declarations, kind);
- }
-
- function parseRestElement(params) {
- var param, node = new Node();
-
- lex();
-
- if (match('{')) {
- throwError(Messages.ObjectPatternAsRestParameter);
- }
-
- params.push(lookahead);
-
- param = parseVariableIdentifier();
-
- if (match('=')) {
- throwError(Messages.DefaultRestParameter);
- }
-
- if (!match(')')) {
- throwError(Messages.ParameterAfterRestParameter);
- }
-
- return node.finishRestElement(param);
- }
-
- // ECMA-262 13.4 Empty Statement
-
- function parseEmptyStatement(node) {
- expect(';');
- return node.finishEmptyStatement();
- }
-
- // ECMA-262 12.4 Expression Statement
-
- function parseExpressionStatement(node) {
- var expr = parseExpression();
- consumeSemicolon();
- return node.finishExpressionStatement(expr);
- }
-
- // ECMA-262 13.6 If statement
-
- function parseIfStatement(node) {
- var test, consequent, alternate;
-
- expectKeyword('if');
-
- expect('(');
-
- test = parseExpression();
-
- expect(')');
-
- consequent = parseStatement();
-
- if (matchKeyword('else')) {
- lex();
- alternate = parseStatement();
- } else {
- alternate = null;
- }
-
- return node.finishIfStatement(test, consequent, alternate);
- }
-
- // ECMA-262 13.7 Iteration Statements
-
- function parseDoWhileStatement(node) {
- var body, test, oldInIteration;
-
- expectKeyword('do');
-
- oldInIteration = state.inIteration;
- state.inIteration = true;
-
- body = parseStatement();
-
- state.inIteration = oldInIteration;
-
- expectKeyword('while');
-
- expect('(');
-
- test = parseExpression();
-
- expect(')');
-
- if (match(';')) {
- lex();
- }
-
- return node.finishDoWhileStatement(body, test);
- }
-
- function parseWhileStatement(node) {
- var test, body, oldInIteration;
-
- expectKeyword('while');
-
- expect('(');
-
- test = parseExpression();
-
- expect(')');
-
- oldInIteration = state.inIteration;
- state.inIteration = true;
-
- body = parseStatement();
-
- state.inIteration = oldInIteration;
-
- return node.finishWhileStatement(test, body);
- }
-
- function parseForStatement(node) {
- var init, forIn, initSeq, initStartToken, test, update, left, right, kind, declarations,
- body, oldInIteration, previousAllowIn = state.allowIn;
-
- init = test = update = null;
- forIn = true;
-
- expectKeyword('for');
-
- expect('(');
-
- if (match(';')) {
- lex();
- } else {
- if (matchKeyword('var')) {
- init = new Node();
- lex();
-
- state.allowIn = false;
- declarations = parseVariableDeclarationList({ inFor: true });
- state.allowIn = previousAllowIn;
-
- if (declarations.length === 1 && matchKeyword('in')) {
- init = init.finishVariableDeclaration(declarations);
- lex();
- left = init;
- right = parseExpression();
- init = null;
- } else if (declarations.length === 1 && declarations[0].init === null && matchContextualKeyword('of')) {
- init = init.finishVariableDeclaration(declarations);
- lex();
- left = init;
- right = parseAssignmentExpression();
- init = null;
- forIn = false;
- } else {
- init = init.finishVariableDeclaration(declarations);
- expect(';');
- }
- } else if (matchKeyword('const') || matchKeyword('let')) {
- init = new Node();
- kind = lex().value;
-
- if (!strict && lookahead.value === 'in') {
- init = init.finishIdentifier(kind);
- lex();
- left = init;
- right = parseExpression();
- init = null;
- } else {
- state.allowIn = false;
- declarations = parseBindingList(kind, {inFor: true});
- state.allowIn = previousAllowIn;
-
- if (declarations.length === 1 && declarations[0].init === null && matchKeyword('in')) {
- init = init.finishLexicalDeclaration(declarations, kind);
- lex();
- left = init;
- right = parseExpression();
- init = null;
- } else if (declarations.length === 1 && declarations[0].init === null && matchContextualKeyword('of')) {
- init = init.finishLexicalDeclaration(declarations, kind);
- lex();
- left = init;
- right = parseAssignmentExpression();
- init = null;
- forIn = false;
- } else {
- consumeSemicolon();
- init = init.finishLexicalDeclaration(declarations, kind);
- }
- }
- } else {
- initStartToken = lookahead;
- state.allowIn = false;
- init = inheritCoverGrammar(parseAssignmentExpression);
- state.allowIn = previousAllowIn;
-
- if (matchKeyword('in')) {
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInForIn);
- }
-
- lex();
- reinterpretExpressionAsPattern(init);
- left = init;
- right = parseExpression();
- init = null;
- } else if (matchContextualKeyword('of')) {
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInForLoop);
- }
-
- lex();
- reinterpretExpressionAsPattern(init);
- left = init;
- right = parseAssignmentExpression();
- init = null;
- forIn = false;
- } else {
- if (match(',')) {
- initSeq = [init];
- while (match(',')) {
- lex();
- initSeq.push(isolateCoverGrammar(parseAssignmentExpression));
- }
- init = new WrappingNode(initStartToken).finishSequenceExpression(initSeq);
- }
- expect(';');
- }
- }
- }
-
- if (typeof left === 'undefined') {
-
- if (!match(';')) {
- test = parseExpression();
- }
- expect(';');
-
- if (!match(')')) {
- update = parseExpression();
- }
- }
-
- expect(')');
-
- oldInIteration = state.inIteration;
- state.inIteration = true;
-
- body = isolateCoverGrammar(parseStatement);
-
- state.inIteration = oldInIteration;
-
- return (typeof left === 'undefined') ?
- node.finishForStatement(init, test, update, body) :
- forIn ? node.finishForInStatement(left, right, body) :
- node.finishForOfStatement(left, right, body);
- }
-
- // ECMA-262 13.8 The continue statement
-
- function parseContinueStatement(node) {
- var label = null, key;
-
- expectKeyword('continue');
-
- // Optimize the most common form: 'continue;'.
- if (source.charCodeAt(startIndex) === 0x3B) {
- lex();
-
- if (!state.inIteration) {
- throwError(Messages.IllegalContinue);
- }
-
- return node.finishContinueStatement(null);
- }
-
- if (hasLineTerminator) {
- if (!state.inIteration) {
- throwError(Messages.IllegalContinue);
- }
-
- return node.finishContinueStatement(null);
- }
-
- if (lookahead.type === Token.Identifier) {
- label = parseVariableIdentifier();
-
- key = '$' + label.name;
- if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
- throwError(Messages.UnknownLabel, label.name);
- }
- }
-
- consumeSemicolon();
-
- if (label === null && !state.inIteration) {
- throwError(Messages.IllegalContinue);
- }
-
- return node.finishContinueStatement(label);
- }
-
- // ECMA-262 13.9 The break statement
-
- function parseBreakStatement(node) {
- var label = null, key;
-
- expectKeyword('break');
-
- // Catch the very common case first: immediately a semicolon (U+003B).
- if (source.charCodeAt(lastIndex) === 0x3B) {
- lex();
-
- if (!(state.inIteration || state.inSwitch)) {
- throwError(Messages.IllegalBreak);
- }
-
- return node.finishBreakStatement(null);
- }
-
- if (hasLineTerminator) {
- if (!(state.inIteration || state.inSwitch)) {
- throwError(Messages.IllegalBreak);
- }
- } else if (lookahead.type === Token.Identifier) {
- label = parseVariableIdentifier();
-
- key = '$' + label.name;
- if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
- throwError(Messages.UnknownLabel, label.name);
- }
- }
-
- consumeSemicolon();
-
- if (label === null && !(state.inIteration || state.inSwitch)) {
- throwError(Messages.IllegalBreak);
- }
-
- return node.finishBreakStatement(label);
- }
-
- // ECMA-262 13.10 The return statement
-
- function parseReturnStatement(node) {
- var argument = null;
-
- expectKeyword('return');
-
- if (!state.inFunctionBody) {
- tolerateError(Messages.IllegalReturn);
- }
-
- // 'return' followed by a space and an identifier is very common.
- if (source.charCodeAt(lastIndex) === 0x20) {
- if (isIdentifierStart(source.charCodeAt(lastIndex + 1))) {
- argument = parseExpression();
- consumeSemicolon();
- return node.finishReturnStatement(argument);
- }
- }
-
- if (hasLineTerminator) {
- // HACK
- return node.finishReturnStatement(null);
- }
-
- if (!match(';')) {
- if (!match('}') && lookahead.type !== Token.EOF) {
- argument = parseExpression();
- }
- }
-
- consumeSemicolon();
-
- return node.finishReturnStatement(argument);
- }
-
- // ECMA-262 13.11 The with statement
-
- function parseWithStatement(node) {
- var object, body;
-
- if (strict) {
- tolerateError(Messages.StrictModeWith);
- }
-
- expectKeyword('with');
-
- expect('(');
-
- object = parseExpression();
-
- expect(')');
-
- body = parseStatement();
-
- return node.finishWithStatement(object, body);
- }
-
- // ECMA-262 13.12 The switch statement
-
- function parseSwitchCase() {
- var test, consequent = [], statement, node = new Node();
-
- if (matchKeyword('default')) {
- lex();
- test = null;
- } else {
- expectKeyword('case');
- test = parseExpression();
- }
- expect(':');
-
- while (startIndex < length) {
- if (match('}') || matchKeyword('default') || matchKeyword('case')) {
- break;
- }
- statement = parseStatementListItem();
- consequent.push(statement);
- }
-
- return node.finishSwitchCase(test, consequent);
- }
-
- function parseSwitchStatement(node) {
- var discriminant, cases, clause, oldInSwitch, defaultFound;
-
- expectKeyword('switch');
-
- expect('(');
-
- discriminant = parseExpression();
-
- expect(')');
-
- expect('{');
-
- cases = [];
-
- if (match('}')) {
- lex();
- return node.finishSwitchStatement(discriminant, cases);
- }
-
- oldInSwitch = state.inSwitch;
- state.inSwitch = true;
- defaultFound = false;
-
- while (startIndex < length) {
- if (match('}')) {
- break;
- }
- clause = parseSwitchCase();
- if (clause.test === null) {
- if (defaultFound) {
- throwError(Messages.MultipleDefaultsInSwitch);
- }
- defaultFound = true;
- }
- cases.push(clause);
- }
-
- state.inSwitch = oldInSwitch;
-
- expect('}');
-
- return node.finishSwitchStatement(discriminant, cases);
- }
-
- // ECMA-262 13.14 The throw statement
-
- function parseThrowStatement(node) {
- var argument;
-
- expectKeyword('throw');
-
- if (hasLineTerminator) {
- throwError(Messages.NewlineAfterThrow);
- }
-
- argument = parseExpression();
-
- consumeSemicolon();
-
- return node.finishThrowStatement(argument);
- }
-
- // ECMA-262 13.15 The try statement
-
- function parseCatchClause() {
- var param, params = [], paramMap = {}, key, i, body, node = new Node();
-
- expectKeyword('catch');
-
- expect('(');
- if (match(')')) {
- throwUnexpectedToken(lookahead);
- }
-
- param = parsePattern(params);
- for (i = 0; i < params.length; i++) {
- key = '$' + params[i].value;
- if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
- tolerateError(Messages.DuplicateBinding, params[i].value);
- }
- paramMap[key] = true;
- }
-
- // ECMA-262 12.14.1
- if (strict && isRestrictedWord(param.name)) {
- tolerateError(Messages.StrictCatchVariable);
- }
-
- expect(')');
- body = parseBlock();
- return node.finishCatchClause(param, body);
- }
-
- function parseTryStatement(node) {
- var block, handler = null, finalizer = null;
-
- expectKeyword('try');
-
- block = parseBlock();
-
- if (matchKeyword('catch')) {
- handler = parseCatchClause();
- }
-
- if (matchKeyword('finally')) {
- lex();
- finalizer = parseBlock();
- }
-
- if (!handler && !finalizer) {
- throwError(Messages.NoCatchOrFinally);
- }
-
- return node.finishTryStatement(block, handler, finalizer);
- }
-
- // ECMA-262 13.16 The debugger statement
-
- function parseDebuggerStatement(node) {
- expectKeyword('debugger');
-
- consumeSemicolon();
-
- return node.finishDebuggerStatement();
- }
-
- // 13 Statements
-
- function parseStatement() {
- var type = lookahead.type,
- expr,
- labeledBody,
- key,
- node;
-
- if (type === Token.EOF) {
- throwUnexpectedToken(lookahead);
- }
-
- if (type === Token.Punctuator && lookahead.value === '{') {
- return parseBlock();
- }
- isAssignmentTarget = isBindingElement = true;
- node = new Node();
-
- if (type === Token.Punctuator) {
- switch (lookahead.value) {
- case ';':
- return parseEmptyStatement(node);
- case '(':
- return parseExpressionStatement(node);
- default:
- break;
- }
- } else if (type === Token.Keyword) {
- switch (lookahead.value) {
- case 'break':
- return parseBreakStatement(node);
- case 'continue':
- return parseContinueStatement(node);
- case 'debugger':
- return parseDebuggerStatement(node);
- case 'do':
- return parseDoWhileStatement(node);
- case 'for':
- return parseForStatement(node);
- case 'function':
- return parseFunctionDeclaration(node);
- case 'if':
- return parseIfStatement(node);
- case 'return':
- return parseReturnStatement(node);
- case 'switch':
- return parseSwitchStatement(node);
- case 'throw':
- return parseThrowStatement(node);
- case 'try':
- return parseTryStatement(node);
- case 'var':
- return parseVariableStatement(node);
- case 'while':
- return parseWhileStatement(node);
- case 'with':
- return parseWithStatement(node);
- default:
- break;
- }
- }
-
- expr = parseExpression();
-
- // ECMA-262 12.12 Labelled Statements
- if ((expr.type === Syntax.Identifier) && match(':')) {
- lex();
-
- key = '$' + expr.name;
- if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
- throwError(Messages.Redeclaration, 'Label', expr.name);
- }
-
- state.labelSet[key] = true;
- labeledBody = parseStatement();
- delete state.labelSet[key];
- return node.finishLabeledStatement(expr, labeledBody);
- }
-
- consumeSemicolon();
-
- return node.finishExpressionStatement(expr);
- }
-
- // ECMA-262 14.1 Function Definition
-
- function parseFunctionSourceElements() {
- var statement, body = [], token, directive, firstRestricted,
- oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody,
- node = new Node();
-
- expect('{');
-
- while (startIndex < length) {
- if (lookahead.type !== Token.StringLiteral) {
- break;
- }
- token = lookahead;
-
- statement = parseStatementListItem();
- body.push(statement);
- if (statement.expression.type !== Syntax.Literal) {
- // this is not directive
- break;
- }
- directive = source.slice(token.start + 1, token.end - 1);
- if (directive === 'use strict') {
- strict = true;
- if (firstRestricted) {
- tolerateUnexpectedToken(firstRestricted, Messages.StrictOctalLiteral);
- }
- } else {
- if (!firstRestricted && token.octal) {
- firstRestricted = token;
- }
- }
- }
-
- oldLabelSet = state.labelSet;
- oldInIteration = state.inIteration;
- oldInSwitch = state.inSwitch;
- oldInFunctionBody = state.inFunctionBody;
-
- state.labelSet = {};
- state.inIteration = false;
- state.inSwitch = false;
- state.inFunctionBody = true;
-
- while (startIndex < length) {
- if (match('}')) {
- break;
- }
- body.push(parseStatementListItem());
- }
-
- expect('}');
-
- state.labelSet = oldLabelSet;
- state.inIteration = oldInIteration;
- state.inSwitch = oldInSwitch;
- state.inFunctionBody = oldInFunctionBody;
-
- return node.finishBlockStatement(body);
- }
-
- function validateParam(options, param, name) {
- var key = '$' + name;
- if (strict) {
- if (isRestrictedWord(name)) {
- options.stricted = param;
- options.message = Messages.StrictParamName;
- }
- if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
- options.stricted = param;
- options.message = Messages.StrictParamDupe;
- }
- } else if (!options.firstRestricted) {
- if (isRestrictedWord(name)) {
- options.firstRestricted = param;
- options.message = Messages.StrictParamName;
- } else if (isStrictModeReservedWord(name)) {
- options.firstRestricted = param;
- options.message = Messages.StrictReservedWord;
- } else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
- options.stricted = param;
- options.message = Messages.StrictParamDupe;
- }
- }
- options.paramSet[key] = true;
- }
-
- function parseParam(options) {
- var token, param, params = [], i, def;
-
- token = lookahead;
- if (token.value === '...') {
- param = parseRestElement(params);
- validateParam(options, param.argument, param.argument.name);
- options.params.push(param);
- options.defaults.push(null);
- return false;
- }
-
- param = parsePatternWithDefault(params);
- for (i = 0; i < params.length; i++) {
- validateParam(options, params[i], params[i].value);
- }
-
- if (param.type === Syntax.AssignmentPattern) {
- def = param.right;
- param = param.left;
- ++options.defaultCount;
- }
-
- options.params.push(param);
- options.defaults.push(def);
-
- return !match(')');
- }
-
- function parseParams(firstRestricted) {
- var options;
-
- options = {
- params: [],
- defaultCount: 0,
- defaults: [],
- firstRestricted: firstRestricted
- };
-
- expect('(');
-
- if (!match(')')) {
- options.paramSet = {};
- while (startIndex < length) {
- if (!parseParam(options)) {
- break;
- }
- expect(',');
- }
- }
-
- expect(')');
-
- if (options.defaultCount === 0) {
- options.defaults = [];
- }
-
- return {
- params: options.params,
- defaults: options.defaults,
- stricted: options.stricted,
- firstRestricted: options.firstRestricted,
- message: options.message
- };
- }
-
- function parseFunctionDeclaration(node, identifierIsOptional) {
- var id = null, params = [], defaults = [], body, token, stricted, tmp, firstRestricted, message, previousStrict,
- isGenerator, previousAllowYield;
-
- previousAllowYield = state.allowYield;
-
- expectKeyword('function');
-
- isGenerator = match('*');
- if (isGenerator) {
- lex();
- }
-
- if (!identifierIsOptional || !match('(')) {
- token = lookahead;
- id = parseVariableIdentifier();
- if (strict) {
- if (isRestrictedWord(token.value)) {
- tolerateUnexpectedToken(token, Messages.StrictFunctionName);
- }
- } else {
- if (isRestrictedWord(token.value)) {
- firstRestricted = token;
- message = Messages.StrictFunctionName;
- } else if (isStrictModeReservedWord(token.value)) {
- firstRestricted = token;
- message = Messages.StrictReservedWord;
- }
- }
- }
-
- state.allowYield = !isGenerator;
- tmp = parseParams(firstRestricted);
- params = tmp.params;
- defaults = tmp.defaults;
- stricted = tmp.stricted;
- firstRestricted = tmp.firstRestricted;
- if (tmp.message) {
- message = tmp.message;
- }
-
-
- previousStrict = strict;
- body = parseFunctionSourceElements();
- if (strict && firstRestricted) {
- throwUnexpectedToken(firstRestricted, message);
- }
- if (strict && stricted) {
- tolerateUnexpectedToken(stricted, message);
- }
-
- strict = previousStrict;
- state.allowYield = previousAllowYield;
-
- return node.finishFunctionDeclaration(id, params, defaults, body, isGenerator);
- }
-
- function parseFunctionExpression() {
- var token, id = null, stricted, firstRestricted, message, tmp,
- params = [], defaults = [], body, previousStrict, node = new Node(),
- isGenerator, previousAllowYield;
-
- previousAllowYield = state.allowYield;
-
- expectKeyword('function');
-
- isGenerator = match('*');
- if (isGenerator) {
- lex();
- }
-
- state.allowYield = !isGenerator;
- if (!match('(')) {
- token = lookahead;
- id = (!strict && !isGenerator && matchKeyword('yield')) ? parseNonComputedProperty() : parseVariableIdentifier();
- if (strict) {
- if (isRestrictedWord(token.value)) {
- tolerateUnexpectedToken(token, Messages.StrictFunctionName);
- }
- } else {
- if (isRestrictedWord(token.value)) {
- firstRestricted = token;
- message = Messages.StrictFunctionName;
- } else if (isStrictModeReservedWord(token.value)) {
- firstRestricted = token;
- message = Messages.StrictReservedWord;
- }
- }
- }
-
- tmp = parseParams(firstRestricted);
- params = tmp.params;
- defaults = tmp.defaults;
- stricted = tmp.stricted;
- firstRestricted = tmp.firstRestricted;
- if (tmp.message) {
- message = tmp.message;
- }
-
- previousStrict = strict;
- body = parseFunctionSourceElements();
- if (strict && firstRestricted) {
- throwUnexpectedToken(firstRestricted, message);
- }
- if (strict && stricted) {
- tolerateUnexpectedToken(stricted, message);
- }
- strict = previousStrict;
- state.allowYield = previousAllowYield;
-
- return node.finishFunctionExpression(id, params, defaults, body, isGenerator);
- }
-
- // ECMA-262 14.5 Class Definitions
-
- function parseClassBody() {
- var classBody, token, isStatic, hasConstructor = false, body, method, computed, key;
-
- classBody = new Node();
-
- expect('{');
- body = [];
- while (!match('}')) {
- if (match(';')) {
- lex();
- } else {
- method = new Node();
- token = lookahead;
- isStatic = false;
- computed = match('[');
- if (match('*')) {
- lex();
- } else {
- key = parseObjectPropertyKey();
- if (key.name === 'static' && (lookaheadPropertyName() || match('*'))) {
- token = lookahead;
- isStatic = true;
- computed = match('[');
- if (match('*')) {
- lex();
- } else {
- key = parseObjectPropertyKey();
- }
- }
- }
- method = tryParseMethodDefinition(token, key, computed, method);
- if (method) {
- method['static'] = isStatic; // jscs:ignore requireDotNotation
- if (method.kind === 'init') {
- method.kind = 'method';
- }
- if (!isStatic) {
- if (!method.computed && (method.key.name || method.key.value.toString()) === 'constructor') {
- if (method.kind !== 'method' || !method.method || method.value.generator) {
- throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);
- }
- if (hasConstructor) {
- throwUnexpectedToken(token, Messages.DuplicateConstructor);
- } else {
- hasConstructor = true;
- }
- method.kind = 'constructor';
- }
- } else {
- if (!method.computed && (method.key.name || method.key.value.toString()) === 'prototype') {
- throwUnexpectedToken(token, Messages.StaticPrototype);
- }
- }
- method.type = Syntax.MethodDefinition;
- delete method.method;
- delete method.shorthand;
- body.push(method);
- } else {
- throwUnexpectedToken(lookahead);
- }
- }
- }
- lex();
- return classBody.finishClassBody(body);
- }
-
- function parseClassDeclaration(identifierIsOptional) {
- var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;
- strict = true;
-
- expectKeyword('class');
-
- if (!identifierIsOptional || lookahead.type === Token.Identifier) {
- id = parseVariableIdentifier();
- }
-
- if (matchKeyword('extends')) {
- lex();
- superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);
- }
- classBody = parseClassBody();
- strict = previousStrict;
-
- return classNode.finishClassDeclaration(id, superClass, classBody);
- }
-
- function parseClassExpression() {
- var id = null, superClass = null, classNode = new Node(), classBody, previousStrict = strict;
- strict = true;
-
- expectKeyword('class');
-
- if (lookahead.type === Token.Identifier) {
- id = parseVariableIdentifier();
- }
-
- if (matchKeyword('extends')) {
- lex();
- superClass = isolateCoverGrammar(parseLeftHandSideExpressionAllowCall);
- }
- classBody = parseClassBody();
- strict = previousStrict;
-
- return classNode.finishClassExpression(id, superClass, classBody);
- }
-
- // ECMA-262 15.2 Modules
-
- function parseModuleSpecifier() {
- var node = new Node();
-
- if (lookahead.type !== Token.StringLiteral) {
- throwError(Messages.InvalidModuleSpecifier);
- }
- return node.finishLiteral(lex());
- }
-
- // ECMA-262 15.2.3 Exports
-
- function parseExportSpecifier() {
- var exported, local, node = new Node(), def;
- if (matchKeyword('default')) {
- // export {default} from 'something';
- def = new Node();
- lex();
- local = def.finishIdentifier('default');
- } else {
- local = parseVariableIdentifier();
- }
- if (matchContextualKeyword('as')) {
- lex();
- exported = parseNonComputedProperty();
- }
- return node.finishExportSpecifier(local, exported);
- }
-
- function parseExportNamedDeclaration(node) {
- var declaration = null,
- isExportFromIdentifier,
- src = null, specifiers = [];
-
- // non-default export
- if (lookahead.type === Token.Keyword) {
- // covers:
- // export var f = 1;
- switch (lookahead.value) {
- case 'let':
- case 'const':
- declaration = parseLexicalDeclaration({inFor: false});
- return node.finishExportNamedDeclaration(declaration, specifiers, null);
- case 'var':
- case 'class':
- case 'function':
- declaration = parseStatementListItem();
- return node.finishExportNamedDeclaration(declaration, specifiers, null);
- }
- }
-
- expect('{');
- while (!match('}')) {
- isExportFromIdentifier = isExportFromIdentifier || matchKeyword('default');
- specifiers.push(parseExportSpecifier());
- if (!match('}')) {
- expect(',');
- if (match('}')) {
- break;
- }
- }
- }
- expect('}');
-
- if (matchContextualKeyword('from')) {
- // covering:
- // export {default} from 'foo';
- // export {foo} from 'foo';
- lex();
- src = parseModuleSpecifier();
- consumeSemicolon();
- } else if (isExportFromIdentifier) {
- // covering:
- // export {default}; // missing fromClause
- throwError(lookahead.value ?
- Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
- } else {
- // cover
- // export {foo};
- consumeSemicolon();
- }
- return node.finishExportNamedDeclaration(declaration, specifiers, src);
- }
-
- function parseExportDefaultDeclaration(node) {
- var declaration = null,
- expression = null;
-
- // covers:
- // export default ...
- expectKeyword('default');
-
- if (matchKeyword('function')) {
- // covers:
- // export default function foo () {}
- // export default function () {}
- declaration = parseFunctionDeclaration(new Node(), true);
- return node.finishExportDefaultDeclaration(declaration);
- }
- if (matchKeyword('class')) {
- declaration = parseClassDeclaration(true);
- return node.finishExportDefaultDeclaration(declaration);
- }
-
- if (matchContextualKeyword('from')) {
- throwError(Messages.UnexpectedToken, lookahead.value);
- }
-
- // covers:
- // export default {};
- // export default [];
- // export default (1 + 2);
- if (match('{')) {
- expression = parseObjectInitializer();
- } else if (match('[')) {
- expression = parseArrayInitializer();
- } else {
- expression = parseAssignmentExpression();
- }
- consumeSemicolon();
- return node.finishExportDefaultDeclaration(expression);
- }
-
- function parseExportAllDeclaration(node) {
- var src;
-
- // covers:
- // export * from 'foo';
- expect('*');
- if (!matchContextualKeyword('from')) {
- throwError(lookahead.value ?
- Messages.UnexpectedToken : Messages.MissingFromClause, lookahead.value);
- }
- lex();
- src = parseModuleSpecifier();
- consumeSemicolon();
-
- return node.finishExportAllDeclaration(src);
- }
-
- function parseExportDeclaration() {
- var node = new Node();
- if (state.inFunctionBody) {
- throwError(Messages.IllegalExportDeclaration);
- }
-
- expectKeyword('export');
-
- if (matchKeyword('default')) {
- return parseExportDefaultDeclaration(node);
- }
- if (match('*')) {
- return parseExportAllDeclaration(node);
- }
- return parseExportNamedDeclaration(node);
- }
-
- // ECMA-262 15.2.2 Imports
-
- function parseImportSpecifier() {
- // import {{$item.title} | +|
{$item.title|htmlentities} |
{switch $item.type}
{case string}
-
+
{/case}
{case password}
-
+
{/case}
{case text}
-
+
{/case}
{case array}
-
diff --git a/application/admin/view/addon/index.html b/application/admin/view/addon/index.html
index e72defafdfbe16ab2bfcf14dd20498a1aac79d97..f1d7d00f3317bbce5bdf72b036fec8853ceebeae 100644
--- a/application/admin/view/addon/index.html
+++ b/application/admin/view/addon/index.html
@@ -136,7 +136,7 @@
-
+
diff --git a/application/admin/view/auth/admin/edit.html b/application/admin/view/auth/admin/edit.html
index a36d0096f67f1d008b19657da63ac5a4b2fab363..20c7a45db47232e6819679dcc78f68fba20997a1 100644
--- a/application/admin/view/auth/admin/edit.html
+++ b/application/admin/view/auth/admin/edit.html
@@ -39,7 +39,7 @@
-
+
diff --git a/application/admin/view/auth/rule/edit.html b/application/admin/view/auth/rule/edit.html
index 658a408b15b05d514622f20fd28ae0aef2b2eaa4..0aee82fbd9d1211352efe9da2866ca4cf2de46cb 100644
--- a/application/admin/view/auth/rule/edit.html
+++ b/application/admin/view/auth/rule/edit.html
@@ -34,8 +34,8 @@
-
+
diff --git a/application/admin/view/category/add.html b/application/admin/view/category/add.html
index e92f56c71ee511d12c041edc7419db6a68a3c5af..4cd514eaba9a75c2d6c5bd46325ba6aa390f8666 100644
--- a/application/admin/view/category/add.html
+++ b/application/admin/view/category/add.html
@@ -10,7 +10,7 @@
-
+
@@ -77,7 +77,7 @@
-
+
diff --git a/application/admin/view/category/index.html b/application/admin/view/category/index.html
index c257520b83ecec5ddb94ae8602c9b60f40af9bde..085bb0201d72f1eae250a498751eda38196f9be6 100644
--- a/application/admin/view/category/index.html
+++ b/application/admin/view/category/index.html
@@ -4,7 +4,7 @@
{:__('Layout Options')}-{:__("Simple nav tips")} {:__("Toggle the top menu state (multiple or single)")} {:__("Always show multiple tab when multiple nav is set")} {:__("Toggle the top menu state (multiple or single)")} {:__("Always show multiple tab when multiple nav is set")} {:__("Toggle the left sidebar's state (open or collapse)")} {:__('Let the sidebar mini expand on hover')} {:__('Always show sub menu')}
@@ -119,10 +117,10 @@
- {$totaluser}
+ {$totaluser|htmlentities}
{:__('Total user')}
- {$totaladdon}
+ {$totaladdon|htmlentities}
{:__('Total addon')}
- {$attachmentnums}
+ {$attachmentnums|htmlentities}
{:__('Total attachment')}
- {$totaladmin}
+ {$totaladmin|htmlentities}
{:__('Total admin')}
-
{$todayusersignup}
+ {$todayusersignup|htmlentities}
{:__('Today user signup')}
@@ -231,7 +231,7 @@
-
{$todayuserlogin}
+ {$todayuserlogin|htmlentities}
{:__('Today user login')}
@@ -241,7 +241,7 @@
-
{$threednu}
+ {$threednu|htmlentities}
{:__('Three dnu')}
@@ -251,7 +251,7 @@
-
{$sevendnu}
+ {$sevendnu|htmlentities}
{:__('Seven dnu')}
@@ -261,7 +261,7 @@
-
{$sevendau}
+ {$sevendau|htmlentities}
{:__('Seven dau')}
@@ -271,7 +271,7 @@
-
{$thirtydau}
+ {$thirtydau|htmlentities}
{:__('Thirty dau')}
@@ -298,7 +298,7 @@
- {$totalworkingaddon}+{$totalworkingaddon|htmlentities}
{:__('Working addon count tips')}
@@ -318,7 +318,7 @@
- {$dbtablenums}+{$dbtablenums|htmlentities}
{:__('Database table nums')}
@@ -346,7 +346,7 @@
-
@@ -22,13 +22,13 @@
{$attachmentnums}+{$attachmentnums|htmlentities}
{:__('Attachment nums')}
@@ -373,7 +373,7 @@
-
@@ -42,7 +42,7 @@
{$picturenums}+{$picturenums|htmlentities}
{:__('Picture nums')}
diff --git a/application/admin/view/general/attachment/add.html b/application/admin/view/general/attachment/add.html
index f98f2834da280df3ad4fa1f6a073c83cd53a6b2b..f535e16a99cc9de51b59af6a7a822f2dacb6c0bf 100644
--- a/application/admin/view/general/attachment/add.html
+++ b/application/admin/view/general/attachment/add.html
@@ -15,7 +15,7 @@
-
+
-
+
@@ -40,7 +40,7 @@
-
+
@@ -52,7 +52,7 @@
-
+
@@ -76,7 +76,7 @@
-
+
diff --git a/application/admin/view/general/attachment/index.html b/application/admin/view/general/attachment/index.html
index c06c998fb65f83d2eb48eb8a7114ffb5d9119b8e..126febc62b6b23d7a7464808110ac90aebd23246 100644
--- a/application/admin/view/general/attachment/index.html
+++ b/application/admin/view/general/attachment/index.html
@@ -5,14 +5,14 @@
diff --git a/application/admin/view/general/attachment/select.html b/application/admin/view/general/attachment/select.html
index fdc14f227a5bed515de3b9c1f0d9c6e752ed7341..352f3628ecefe6447cfb3036305f50a79e719b55 100644
--- a/application/admin/view/general/attachment/select.html
+++ b/application/admin/view/general/attachment/select.html
@@ -9,7 +9,7 @@
|