diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6ad91069033..6049b004b0b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -413,7 +413,7 @@ const _super = (function (geti, seti) { * * NOTE: Do not call this method directly. It is part of the emit pipeline * and should only be called indirectly from pipelineEmitWithSourceMap or - * pipelineEmitInUnspecifiedContext (when pickign a more specific context). + * pipelineEmitInUnspecifiedContext (when picking a more specific context). */ function pipelineEmitWithSubstitution(emitContext: EmitContext, node: Node) { emitNodeWithSubstitution(emitContext, node, pipelineEmitForContext); @@ -1172,7 +1172,7 @@ const _super = (function (geti, seti) { const text = getLiteralTextOfNode(expression); return text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0; } - else { + else if (isPropertyAccessExpression(expression) || isElementAccessExpression(expression)) { // check if constant enum value is integer const constantValue = getConstantValue(expression); // isFinite handles cases when constantValue is undefined diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index fd00a051dcb..d873c3ef877 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2798,17 +2798,20 @@ namespace ts { return tokenSourceMapRanges && tokenSourceMapRanges[token]; } - export function getConstantValue(node: Node) { + /** + * Gets the constant value to emit for an expression. + */ + export function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression) { const emitNode = node.emitNode; - if (emitNode && emitNode.flags & EmitFlags.ConstantValue) { - return emitNode.constantValue; - } + return emitNode && emitNode.constantValue; } - export function setConstantValue(node: Node, value: number) { + /** + * Sets the constant value to emit for an expression. + */ + export function setConstantValue(node: PropertyAccessExpression | ElementAccessExpression, value: number) { const emitNode = getOrCreateEmitNode(node); emitNode.constantValue = value; - emitNode.flags |= EmitFlags.ConstantValue; return node; } diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index d6e6501c598..46db5188e33 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -348,7 +348,7 @@ namespace ts { } /** - * Emits a token of a node node with possible leading and trailing source maps. + * Emits a token of a node with possible leading and trailing source maps. * * @param node The node containing the token. * @param token The token to emit. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 316f8b2b2c0..192367348db 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3205,7 +3205,6 @@ namespace ts { AsyncFunctionBody = 1 << 21, ReuseTempVariableScope = 1 << 22, // Reuse the existing temp variable scope during emit. CustomPrologue = 1 << 23, // Treat the statement as if it were a prologue directive (NOTE: Prologue directives are *not* transformed). - ConstantValue = 1 << 24, // The node was replaced with a constant value during substitution. } /* @internal */