Skip to content

Commit

Permalink
Add browser globals to known globals and prevent "typeof" side-effects (
Browse files Browse the repository at this point in the history
#3117)

* "typeof" does not trigger global access side-effects

* Extend known globals to include browser globals

* Add placeholders for global variables

* Move comment
  • Loading branch information
lukastaegert committed Sep 16, 2019
1 parent 13b27ca commit 86d98cb
Show file tree
Hide file tree
Showing 5 changed files with 748 additions and 141 deletions.
4 changes: 3 additions & 1 deletion src/ast/nodes/UnaryExpression.ts
Expand Up @@ -2,6 +2,7 @@ import { DeoptimizableEntity } from '../DeoptimizableEntity';
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import { ImmutableEntityPathTracker } from '../utils/ImmutableEntityPathTracker';
import { EMPTY_PATH, LiteralValueOrUnknown, ObjectPath, UNKNOWN_VALUE } from '../values';
import Identifier from './Identifier';
import { LiteralValue } from './Literal';
import * as NodeType from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
Expand All @@ -20,7 +21,7 @@ const unaryOperators: {

export default class UnaryExpression extends NodeBase {
argument!: ExpressionNode;
operator!: keyof typeof unaryOperators;
operator!: '!' | '+' | '-' | 'delete' | 'typeof' | 'void' | '~';
prefix!: boolean;
type!: NodeType.tUnaryExpression;

Expand All @@ -44,6 +45,7 @@ export default class UnaryExpression extends NodeBase {
}

hasEffects(options: ExecutionPathOptions): boolean {
if (this.operator === 'typeof' && this.argument instanceof Identifier) return false;
return (
this.argument.hasEffects(options) ||
(this.operator === 'delete' &&
Expand Down

0 comments on commit 86d98cb

Please sign in to comment.