Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add browser globals to known globals and prevent "typeof" side-effects #3117

Merged
merged 4 commits into from Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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