From 4ed5632e4676c028c07bf79afbb6ef3aed1ed11d Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 20 Aug 2019 08:01:00 +0200 Subject: [PATCH] Test or remove some edge-cases --- src/ast/nodes/Identifier.ts | 42 +++++++------------ .../wraps-simplified-expressions/main.js | 7 +++- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/ast/nodes/Identifier.ts b/src/ast/nodes/Identifier.ts index 7c49455cb8c..1b0937baf46 100644 --- a/src/ast/nodes/Identifier.ts +++ b/src/ast/nodes/Identifier.ts @@ -7,13 +7,7 @@ import { DeoptimizableEntity } from '../DeoptimizableEntity'; import { ExecutionPathOptions } from '../ExecutionPathOptions'; import FunctionScope from '../scopes/FunctionScope'; import { ImmutableEntityPathTracker } from '../utils/ImmutableEntityPathTracker'; -import { - EMPTY_PATH, - LiteralValueOrUnknown, - ObjectPath, - UNKNOWN_EXPRESSION, - UNKNOWN_VALUE -} from '../values'; +import { EMPTY_PATH, LiteralValueOrUnknown, ObjectPath } from '../values'; import GlobalVariable from '../variables/GlobalVariable'; import LocalVariable from '../variables/LocalVariable'; import Variable from '../variables/Variable'; @@ -69,24 +63,20 @@ export default class Identifier extends NodeBase implements PatternNode { case 'parameter': variable = (this.scope as FunctionScope).addParameterDeclaration(this); break; + /* istanbul ignore next */ default: - throw new Error(`Unexpected identifier kind ${kind}.`); + /* istanbul ignore next */ + throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`); } return [(this.variable = variable)]; } deoptimizePath(path: ObjectPath) { if (!this.bound) this.bind(); - if (this.variable !== null) { - if ( - path.length === 0 && - this.name in this.context.importDescriptions && - !this.scope.contains(this.name) - ) { - this.disallowImportReassignment(); - } - this.variable.deoptimizePath(path); + if (path.length === 0 && !this.scope.contains(this.name)) { + this.disallowImportReassignment(); } + (this.variable as Variable).deoptimizePath(path); } getLiteralValueAtPath( @@ -95,10 +85,7 @@ export default class Identifier extends NodeBase implements PatternNode { origin: DeoptimizableEntity ): LiteralValueOrUnknown { if (!this.bound) this.bind(); - if (this.variable !== null) { - return this.variable.getLiteralValueAtPath(path, recursionTracker, origin); - } - return UNKNOWN_VALUE; + return (this.variable as Variable).getLiteralValueAtPath(path, recursionTracker, origin); } getReturnExpressionWhenCalledAtPath( @@ -107,10 +94,11 @@ export default class Identifier extends NodeBase implements PatternNode { origin: DeoptimizableEntity ) { if (!this.bound) this.bind(); - if (this.variable !== null) { - return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - } - return UNKNOWN_EXPRESSION; + return (this.variable as Variable).getReturnExpressionWhenCalledAtPath( + path, + recursionTracker, + origin + ); } hasEffects(): boolean { @@ -147,9 +135,7 @@ export default class Identifier extends NodeBase implements PatternNode { } includeCallArguments(args: (ExpressionNode | SpreadElement)[]): void { - if (this.variable) { - this.variable.includeCallArguments(args); - } + (this.variable as Variable).includeCallArguments(args); } render( diff --git a/test/function/samples/wraps-simplified-expressions/main.js b/test/function/samples/wraps-simplified-expressions/main.js index edeac8d4c45..560aedd2b8a 100644 --- a/test/function/samples/wraps-simplified-expressions/main.js +++ b/test/function/samples/wraps-simplified-expressions/main.js @@ -1,6 +1,6 @@ const wrapper = { foo() { - assert.notEqual(this, wrapper) + assert.notEqual(this, wrapper); } }; @@ -12,11 +12,16 @@ const wrapper = { (true && (true ? wrapper.foo : null))(); (true && (1, 2, wrapper.foo))(); +function evoke(callee, arg) { + return callee(arg); +} + // Indirectly invoked eval is executed in the global scope function testEval() { assert.notEqual((true && eval)('this'), 'test'); assert.notEqual((true ? eval : null)('this'), 'test'); assert.notEqual((1, 2, eval)('this'), 'test'); + assert.equal(evoke(true && eval, '42'), '42'); } testEval.call('test');