style: reformat all files using prettier
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { COMPILER_REVISION, REVISION_CHANGES } from '../base';
|
||||
import Exception from '../exception';
|
||||
import {isArray} from '../utils';
|
||||
import { isArray } from '../utils';
|
||||
import CodeGen from './code-gen';
|
||||
import {dangerousPropertyRegex} from '../helpers/lookup';
|
||||
import { dangerousPropertyRegex } from '../helpers/lookup';
|
||||
|
||||
function Literal(value) {
|
||||
this.value = value;
|
||||
@@ -13,9 +13,16 @@ function JavaScriptCompiler() {}
|
||||
JavaScriptCompiler.prototype = {
|
||||
// PUBLIC API: You can override these methods in a subclass to provide
|
||||
// alternative compiled forms for name lookup and buffering semantics
|
||||
nameLookup: function(parent, name/* , type*/) {
|
||||
nameLookup: function(parent, name /* , type*/) {
|
||||
if (dangerousPropertyRegex.test(name)) {
|
||||
const isEnumerable = [ this.aliasable('container.propertyIsEnumerable'), '.call(', parent, ',', JSON.stringify(name), ')'];
|
||||
const isEnumerable = [
|
||||
this.aliasable('container.propertyIsEnumerable'),
|
||||
'.call(',
|
||||
parent,
|
||||
',',
|
||||
JSON.stringify(name),
|
||||
')'
|
||||
];
|
||||
return ['(', isEnumerable, '?', _actualLookup(), ' : undefined)'];
|
||||
}
|
||||
return _actualLookup();
|
||||
@@ -34,7 +41,7 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
compilerInfo: function() {
|
||||
const revision = COMPILER_REVISION,
|
||||
versions = REVISION_CHANGES[revision];
|
||||
versions = REVISION_CHANGES[revision];
|
||||
return [revision, versions];
|
||||
},
|
||||
|
||||
@@ -91,14 +98,18 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
this.compileChildren(environment, options);
|
||||
|
||||
this.useDepths = this.useDepths || environment.useDepths || environment.useDecorators || this.options.compat;
|
||||
this.useDepths =
|
||||
this.useDepths ||
|
||||
environment.useDepths ||
|
||||
environment.useDecorators ||
|
||||
this.options.compat;
|
||||
this.useBlockParams = this.useBlockParams || environment.useBlockParams;
|
||||
|
||||
let opcodes = environment.opcodes,
|
||||
opcode,
|
||||
firstLoc,
|
||||
i,
|
||||
l;
|
||||
opcode,
|
||||
firstLoc,
|
||||
i,
|
||||
l;
|
||||
|
||||
for (i = 0, l = opcodes.length; i < l; i++) {
|
||||
opcode = opcodes[i];
|
||||
@@ -124,9 +135,20 @@ JavaScriptCompiler.prototype = {
|
||||
this.decorators.push('return fn;');
|
||||
|
||||
if (asObject) {
|
||||
this.decorators = Function.apply(this, ['fn', 'props', 'container', 'depth0', 'data', 'blockParams', 'depths', this.decorators.merge()]);
|
||||
this.decorators = Function.apply(this, [
|
||||
'fn',
|
||||
'props',
|
||||
'container',
|
||||
'depth0',
|
||||
'data',
|
||||
'blockParams',
|
||||
'depths',
|
||||
this.decorators.merge()
|
||||
]);
|
||||
} else {
|
||||
this.decorators.prepend('function(fn, props, container, depth0, data, blockParams, depths) {\n');
|
||||
this.decorators.prepend(
|
||||
'function(fn, props, container, depth0, data, blockParams, depths) {\n'
|
||||
);
|
||||
this.decorators.push('}\n');
|
||||
this.decorators = this.decorators.merge();
|
||||
}
|
||||
@@ -146,7 +168,7 @@ JavaScriptCompiler.prototype = {
|
||||
ret.useDecorators = true;
|
||||
}
|
||||
|
||||
let {programs, decorators} = this.context;
|
||||
let { programs, decorators } = this.context;
|
||||
for (i = 0, l = programs.length; i < l; i++) {
|
||||
if (programs[i]) {
|
||||
ret[i] = programs[i];
|
||||
@@ -176,11 +198,11 @@ JavaScriptCompiler.prototype = {
|
||||
if (!asObject) {
|
||||
ret.compiler = JSON.stringify(ret.compiler);
|
||||
|
||||
this.source.currentLocation = {start: {line: 1, column: 0}};
|
||||
this.source.currentLocation = { start: { line: 1, column: 0 } };
|
||||
ret = this.objectLiteral(ret);
|
||||
|
||||
if (options.srcName) {
|
||||
ret = ret.toStringWithSourceMap({file: options.destName});
|
||||
ret = ret.toStringWithSourceMap({ file: options.destName });
|
||||
ret.map = ret.map && ret.map.toString();
|
||||
} else {
|
||||
ret = ret.toString();
|
||||
@@ -221,7 +243,7 @@ JavaScriptCompiler.prototype = {
|
||||
Object.keys(this.aliases).forEach(alias => {
|
||||
let node = this.aliases[alias];
|
||||
if (node.children && node.referenceCount > 1) {
|
||||
varDeclarations += ', alias' + (++aliasCount) + '=' + alias;
|
||||
varDeclarations += ', alias' + ++aliasCount + '=' + alias;
|
||||
node.children[0] = 'alias' + aliasCount;
|
||||
}
|
||||
});
|
||||
@@ -243,18 +265,23 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
return Function.apply(this, params);
|
||||
} else {
|
||||
return this.source.wrap(['function(', params.join(','), ') {\n ', source, '}']);
|
||||
return this.source.wrap([
|
||||
'function(',
|
||||
params.join(','),
|
||||
') {\n ',
|
||||
source,
|
||||
'}'
|
||||
]);
|
||||
}
|
||||
},
|
||||
mergeSource: function(varDeclarations) {
|
||||
let isSimple = this.environment.isSimple,
|
||||
appendOnly = !this.forceBuffer,
|
||||
appendFirst,
|
||||
|
||||
sourceSeen,
|
||||
bufferStart,
|
||||
bufferEnd;
|
||||
this.source.each((line) => {
|
||||
appendOnly = !this.forceBuffer,
|
||||
appendFirst,
|
||||
sourceSeen,
|
||||
bufferStart,
|
||||
bufferEnd;
|
||||
this.source.each(line => {
|
||||
if (line.appendToBuffer) {
|
||||
if (bufferStart) {
|
||||
line.prepend(' + ');
|
||||
@@ -280,7 +307,6 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (appendOnly) {
|
||||
if (bufferStart) {
|
||||
bufferStart.prepend('return ');
|
||||
@@ -289,7 +315,8 @@ JavaScriptCompiler.prototype = {
|
||||
this.source.push('return "";');
|
||||
}
|
||||
} else {
|
||||
varDeclarations += ', buffer = ' + (appendFirst ? '' : this.initializeBuffer());
|
||||
varDeclarations +=
|
||||
', buffer = ' + (appendFirst ? '' : this.initializeBuffer());
|
||||
|
||||
if (bufferStart) {
|
||||
bufferStart.prepend('return buffer + ');
|
||||
@@ -300,7 +327,9 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
|
||||
if (varDeclarations) {
|
||||
this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n'));
|
||||
this.source.prepend(
|
||||
'var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n')
|
||||
);
|
||||
}
|
||||
|
||||
return this.source.merge();
|
||||
@@ -316,8 +345,10 @@ JavaScriptCompiler.prototype = {
|
||||
// replace it on the stack with the result of properly
|
||||
// invoking blockHelperMissing.
|
||||
blockValue: function(name) {
|
||||
let blockHelperMissing = this.aliasable('container.hooks.blockHelperMissing'),
|
||||
params = [this.contextName(0)];
|
||||
let blockHelperMissing = this.aliasable(
|
||||
'container.hooks.blockHelperMissing'
|
||||
),
|
||||
params = [this.contextName(0)];
|
||||
this.setupHelperArgs(name, 0, params);
|
||||
|
||||
let blockName = this.popStack();
|
||||
@@ -334,8 +365,10 @@ JavaScriptCompiler.prototype = {
|
||||
// On stack, after, if lastHelper: value
|
||||
ambiguousBlockValue: function() {
|
||||
// We're being a bit cheeky and reusing the options value from the prior exec
|
||||
let blockHelperMissing = this.aliasable('container.hooks.blockHelperMissing'),
|
||||
params = [this.contextName(0)];
|
||||
let blockHelperMissing = this.aliasable(
|
||||
'container.hooks.blockHelperMissing'
|
||||
),
|
||||
params = [this.contextName(0)];
|
||||
this.setupHelperArgs('', 0, params, true);
|
||||
|
||||
this.flushInline();
|
||||
@@ -344,9 +377,14 @@ JavaScriptCompiler.prototype = {
|
||||
params.splice(1, 0, current);
|
||||
|
||||
this.pushSource([
|
||||
'if (!', this.lastHelper, ') { ',
|
||||
current, ' = ', this.source.functionCall(blockHelperMissing, 'call', params),
|
||||
'}']);
|
||||
'if (!',
|
||||
this.lastHelper,
|
||||
') { ',
|
||||
current,
|
||||
' = ',
|
||||
this.source.functionCall(blockHelperMissing, 'call', params),
|
||||
'}'
|
||||
]);
|
||||
},
|
||||
|
||||
// [appendContent]
|
||||
@@ -376,14 +414,24 @@ JavaScriptCompiler.prototype = {
|
||||
// Otherwise, the empty string is appended
|
||||
append: function() {
|
||||
if (this.isInline()) {
|
||||
this.replaceStack((current) => [' != null ? ', current, ' : ""']);
|
||||
this.replaceStack(current => [' != null ? ', current, ' : ""']);
|
||||
|
||||
this.pushSource(this.appendToBuffer(this.popStack()));
|
||||
} else {
|
||||
let local = this.popStack();
|
||||
this.pushSource(['if (', local, ' != null) { ', this.appendToBuffer(local, undefined, true), ' }']);
|
||||
this.pushSource([
|
||||
'if (',
|
||||
local,
|
||||
' != null) { ',
|
||||
this.appendToBuffer(local, undefined, true),
|
||||
' }'
|
||||
]);
|
||||
if (this.environment.isSimple) {
|
||||
this.pushSource(['else { ', this.appendToBuffer("''", undefined, true), ' }']);
|
||||
this.pushSource([
|
||||
'else { ',
|
||||
this.appendToBuffer("''", undefined, true),
|
||||
' }'
|
||||
]);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -395,8 +443,14 @@ JavaScriptCompiler.prototype = {
|
||||
//
|
||||
// Escape `value` and append it to the buffer
|
||||
appendEscaped: function() {
|
||||
this.pushSource(this.appendToBuffer(
|
||||
[this.aliasable('container.escapeExpression'), '(', this.popStack(), ')']));
|
||||
this.pushSource(
|
||||
this.appendToBuffer([
|
||||
this.aliasable('container.escapeExpression'),
|
||||
'(',
|
||||
this.popStack(),
|
||||
')'
|
||||
])
|
||||
);
|
||||
},
|
||||
|
||||
// [getContext]
|
||||
@@ -480,7 +534,7 @@ JavaScriptCompiler.prototype = {
|
||||
let len = parts.length;
|
||||
for (; i < len; i++) {
|
||||
/* eslint-disable no-loop-func */
|
||||
this.replaceStack((current) => {
|
||||
this.replaceStack(current => {
|
||||
let lookup = this.nameLookup(current, parts[i], type);
|
||||
// We want to ensure that zero and false are handled properly if the context (falsy flag)
|
||||
// needs to have the special handling for these values.
|
||||
@@ -503,7 +557,14 @@ JavaScriptCompiler.prototype = {
|
||||
// If the `value` is a lambda, replace it on the stack by
|
||||
// the return value of the lambda
|
||||
resolvePossibleLambda: function() {
|
||||
this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
|
||||
this.push([
|
||||
this.aliasable('container.lambda'),
|
||||
'(',
|
||||
this.popStack(),
|
||||
', ',
|
||||
this.contextName(0),
|
||||
')'
|
||||
]);
|
||||
},
|
||||
|
||||
// [pushStringParam]
|
||||
@@ -543,7 +604,7 @@ JavaScriptCompiler.prototype = {
|
||||
if (this.hash) {
|
||||
this.hashes.push(this.hash);
|
||||
}
|
||||
this.hash = {values: {}, types: [], contexts: [], ids: []};
|
||||
this.hash = { values: {}, types: [], contexts: [], ids: [] };
|
||||
},
|
||||
popHash: function() {
|
||||
let hash = this.hash;
|
||||
@@ -607,11 +668,16 @@ JavaScriptCompiler.prototype = {
|
||||
// and inserts the decorator into the decorators list.
|
||||
registerDecorator(paramSize, name) {
|
||||
let foundDecorator = this.nameLookup('decorators', name, 'decorator'),
|
||||
options = this.setupHelperArgs(name, paramSize);
|
||||
options = this.setupHelperArgs(name, paramSize);
|
||||
|
||||
this.decorators.push([
|
||||
'fn = ',
|
||||
this.decorators.functionCall(foundDecorator, '', ['fn', 'props', 'container', options]),
|
||||
this.decorators.functionCall(foundDecorator, '', [
|
||||
'fn',
|
||||
'props',
|
||||
'container',
|
||||
options
|
||||
]),
|
||||
' || fn;'
|
||||
]);
|
||||
},
|
||||
@@ -627,21 +693,32 @@ JavaScriptCompiler.prototype = {
|
||||
// If the helper is not found, `helperMissing` is called.
|
||||
invokeHelper: function(paramSize, name, isSimple) {
|
||||
let nonHelper = this.popStack(),
|
||||
helper = this.setupHelper(paramSize, name);
|
||||
helper = this.setupHelper(paramSize, name);
|
||||
|
||||
let possibleFunctionCalls = [];
|
||||
|
||||
if (isSimple) { // direct call to helper
|
||||
if (isSimple) {
|
||||
// direct call to helper
|
||||
possibleFunctionCalls.push(helper.name);
|
||||
}
|
||||
// call a function from the input object
|
||||
possibleFunctionCalls.push(nonHelper);
|
||||
if (!this.options.strict) {
|
||||
possibleFunctionCalls.push(this.aliasable('container.hooks.helperMissing'));
|
||||
possibleFunctionCalls.push(
|
||||
this.aliasable('container.hooks.helperMissing')
|
||||
);
|
||||
}
|
||||
|
||||
let functionLookupCode = ['(', this.itemsSeparatedBy(possibleFunctionCalls, '||'), ')'];
|
||||
let functionCall = this.source.functionCall(functionLookupCode, 'call', helper.callParams);
|
||||
let functionLookupCode = [
|
||||
'(',
|
||||
this.itemsSeparatedBy(possibleFunctionCalls, '||'),
|
||||
')'
|
||||
];
|
||||
let functionCall = this.source.functionCall(
|
||||
functionLookupCode,
|
||||
'call',
|
||||
helper.callParams
|
||||
);
|
||||
this.push(functionCall);
|
||||
},
|
||||
|
||||
@@ -685,22 +762,31 @@ JavaScriptCompiler.prototype = {
|
||||
this.emptyHash();
|
||||
let helper = this.setupHelper(0, name, helperCall);
|
||||
|
||||
let helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
|
||||
let helperName = (this.lastHelper = this.nameLookup(
|
||||
'helpers',
|
||||
name,
|
||||
'helper'
|
||||
));
|
||||
|
||||
let lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')'];
|
||||
if (!this.options.strict) {
|
||||
lookup[0] = '(helper = ';
|
||||
lookup.push(
|
||||
' != null ? helper : ',
|
||||
this.aliasable('container.hooks.helperMissing')
|
||||
' != null ? helper : ',
|
||||
this.aliasable('container.hooks.helperMissing')
|
||||
);
|
||||
}
|
||||
|
||||
this.push([
|
||||
'(', lookup,
|
||||
(helper.paramsInit ? ['),(', helper.paramsInit] : []), '),',
|
||||
'(typeof helper === ', this.aliasable('"function"'), ' ? ',
|
||||
this.source.functionCall('helper', 'call', helper.callParams), ' : helper))'
|
||||
'(',
|
||||
lookup,
|
||||
helper.paramsInit ? ['),(', helper.paramsInit] : [],
|
||||
'),',
|
||||
'(typeof helper === ',
|
||||
this.aliasable('"function"'),
|
||||
' ? ',
|
||||
this.source.functionCall('helper', 'call', helper.callParams),
|
||||
' : helper))'
|
||||
]);
|
||||
},
|
||||
|
||||
@@ -713,7 +799,7 @@ JavaScriptCompiler.prototype = {
|
||||
// and pushes the result of the invocation back.
|
||||
invokePartial: function(isDynamic, name, indent) {
|
||||
let params = [],
|
||||
options = this.setupParams(name, 1, params);
|
||||
options = this.setupParams(name, 1, params);
|
||||
|
||||
if (isDynamic) {
|
||||
name = this.popStack();
|
||||
@@ -750,9 +836,9 @@ JavaScriptCompiler.prototype = {
|
||||
// Pops a value off the stack and assigns it to the current hash
|
||||
assignToHash: function(key) {
|
||||
let value = this.popStack(),
|
||||
context,
|
||||
type,
|
||||
id;
|
||||
context,
|
||||
type,
|
||||
id;
|
||||
|
||||
if (this.trackIds) {
|
||||
id = this.popStack();
|
||||
@@ -778,8 +864,13 @@ JavaScriptCompiler.prototype = {
|
||||
pushId: function(type, name, child) {
|
||||
if (type === 'BlockParam') {
|
||||
this.pushStackLiteral(
|
||||
'blockParams[' + name[0] + '].path[' + name[1] + ']'
|
||||
+ (child ? ' + ' + JSON.stringify('.' + child) : ''));
|
||||
'blockParams[' +
|
||||
name[0] +
|
||||
'].path[' +
|
||||
name[1] +
|
||||
']' +
|
||||
(child ? ' + ' + JSON.stringify('.' + child) : '')
|
||||
);
|
||||
} else if (type === 'PathExpression') {
|
||||
this.pushString(name);
|
||||
} else if (type === 'SubExpression') {
|
||||
@@ -794,7 +885,9 @@ JavaScriptCompiler.prototype = {
|
||||
compiler: JavaScriptCompiler,
|
||||
|
||||
compileChildren: function(environment, options) {
|
||||
let children = environment.children, child, compiler;
|
||||
let children = environment.children,
|
||||
child,
|
||||
compiler;
|
||||
|
||||
for (let i = 0, l = children.length; i < l; i++) {
|
||||
child = children[i];
|
||||
@@ -807,7 +900,12 @@ JavaScriptCompiler.prototype = {
|
||||
let index = this.context.programs.length;
|
||||
child.index = index;
|
||||
child.name = 'program' + index;
|
||||
this.context.programs[index] = compiler.compile(child, options, this.context, !this.precompile);
|
||||
this.context.programs[index] = compiler.compile(
|
||||
child,
|
||||
options,
|
||||
this.context,
|
||||
!this.precompile
|
||||
);
|
||||
this.context.decorators[index] = compiler.decorators;
|
||||
this.context.environments[index] = child;
|
||||
|
||||
@@ -835,7 +933,7 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
programExpression: function(guid) {
|
||||
let child = this.environment.children[guid],
|
||||
programParams = [child.index, 'data', child.blockParams];
|
||||
programParams = [child.index, 'data', child.blockParams];
|
||||
|
||||
if (this.useBlockParams || this.useDepths) {
|
||||
programParams.push('blockParams');
|
||||
@@ -870,7 +968,11 @@ JavaScriptCompiler.prototype = {
|
||||
pushSource: function(source) {
|
||||
if (this.pendingContent) {
|
||||
this.source.push(
|
||||
this.appendToBuffer(this.source.quotedString(this.pendingContent), this.pendingLocation));
|
||||
this.appendToBuffer(
|
||||
this.source.quotedString(this.pendingContent),
|
||||
this.pendingLocation
|
||||
)
|
||||
);
|
||||
this.pendingContent = undefined;
|
||||
}
|
||||
|
||||
@@ -881,9 +983,9 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
replaceStack: function(callback) {
|
||||
let prefix = ['('],
|
||||
stack,
|
||||
createdStack,
|
||||
usedLiteral;
|
||||
stack,
|
||||
createdStack,
|
||||
usedLiteral;
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (!this.isInline()) {
|
||||
@@ -920,7 +1022,9 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
incrStack: function() {
|
||||
this.stackSlot++;
|
||||
if (this.stackSlot > this.stackVars.length) { this.stackVars.push('stack' + this.stackSlot); }
|
||||
if (this.stackSlot > this.stackVars.length) {
|
||||
this.stackVars.push('stack' + this.stackSlot);
|
||||
}
|
||||
return this.topStackName();
|
||||
},
|
||||
topStackName: function() {
|
||||
@@ -947,9 +1051,9 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
popStack: function(wrapped) {
|
||||
let inline = this.isInline(),
|
||||
item = (inline ? this.inlineStack : this.compileStack).pop();
|
||||
item = (inline ? this.inlineStack : this.compileStack).pop();
|
||||
|
||||
if (!wrapped && (item instanceof Literal)) {
|
||||
if (!wrapped && item instanceof Literal) {
|
||||
return item.value;
|
||||
} else {
|
||||
if (!inline) {
|
||||
@@ -964,8 +1068,8 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
topStack: function() {
|
||||
let stack = (this.isInline() ? this.inlineStack : this.compileStack),
|
||||
item = stack[stack.length - 1];
|
||||
let stack = this.isInline() ? this.inlineStack : this.compileStack,
|
||||
item = stack[stack.length - 1];
|
||||
|
||||
/* istanbul ignore if */
|
||||
if (item instanceof Literal) {
|
||||
@@ -1007,9 +1111,13 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
setupHelper: function(paramSize, name, blockHelper) {
|
||||
let params = [],
|
||||
paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper);
|
||||
paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper);
|
||||
let foundHelper = this.nameLookup('helpers', name, 'helper'),
|
||||
callContext = this.aliasable(`${this.contextName(0)} != null ? ${this.contextName(0)} : (container.nullContext || {})`);
|
||||
callContext = this.aliasable(
|
||||
`${this.contextName(0)} != null ? ${this.contextName(
|
||||
0
|
||||
)} : (container.nullContext || {})`
|
||||
);
|
||||
|
||||
return {
|
||||
params: params,
|
||||
@@ -1021,11 +1129,11 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
setupParams: function(helper, paramSize, params) {
|
||||
let options = {},
|
||||
contexts = [],
|
||||
types = [],
|
||||
ids = [],
|
||||
objectArgs = !params,
|
||||
param;
|
||||
contexts = [],
|
||||
types = [],
|
||||
ids = [],
|
||||
objectArgs = !params,
|
||||
param;
|
||||
|
||||
if (objectArgs) {
|
||||
params = [];
|
||||
@@ -1043,7 +1151,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
|
||||
let inverse = this.popStack(),
|
||||
program = this.popStack();
|
||||
program = this.popStack();
|
||||
|
||||
// Avoid setting fn and inverse if neither are set. This allows
|
||||
// helpers to do a check for `if (options.fn)`
|
||||
@@ -1106,7 +1214,6 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
(function() {
|
||||
const reservedWords = (
|
||||
'break else new var' +
|
||||
@@ -1127,21 +1234,24 @@ JavaScriptCompiler.prototype = {
|
||||
' null true false'
|
||||
).split(' ');
|
||||
|
||||
const compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
|
||||
const compilerWords = (JavaScriptCompiler.RESERVED_WORDS = {});
|
||||
|
||||
for (let i = 0, l = reservedWords.length; i < l; i++) {
|
||||
compilerWords[reservedWords[i]] = true;
|
||||
}
|
||||
}());
|
||||
})();
|
||||
|
||||
JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
|
||||
return !JavaScriptCompiler.RESERVED_WORDS[name] && (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/).test(name);
|
||||
return (
|
||||
!JavaScriptCompiler.RESERVED_WORDS[name] &&
|
||||
/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name)
|
||||
);
|
||||
};
|
||||
|
||||
function strictLookup(requireTerminal, compiler, parts, type) {
|
||||
let stack = compiler.popStack(),
|
||||
i = 0,
|
||||
len = parts.length;
|
||||
i = 0,
|
||||
len = parts.length;
|
||||
if (requireTerminal) {
|
||||
len--;
|
||||
}
|
||||
@@ -1151,7 +1261,16 @@ function strictLookup(requireTerminal, compiler, parts, type) {
|
||||
}
|
||||
|
||||
if (requireTerminal) {
|
||||
return [compiler.aliasable('container.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ', ', JSON.stringify(compiler.source.currentLocation), ' )'];
|
||||
return [
|
||||
compiler.aliasable('container.strict'),
|
||||
'(',
|
||||
stack,
|
||||
', ',
|
||||
compiler.quotedString(parts[i]),
|
||||
', ',
|
||||
JSON.stringify(compiler.source.currentLocation),
|
||||
' )'
|
||||
];
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user