diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index cc81f92fbfc..6401c7ed872 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1110,7 +1110,7 @@ namespace ts { } function checkStrictModeNumericLiteral(node: LiteralExpression) { - if (inStrictMode && node.flags & NodeFlags.OctalLiteral) { + if (inStrictMode && node.isOctalLiteral) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode)); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db3517970d9..88f000c5a74 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16749,7 +16749,7 @@ namespace ts { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, (prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); if (name.kind === SyntaxKind.NumericLiteral) { - checkGrammarNumericLiteral(name); + checkGrammarNumericLiteral(name); } currentKind = Property; } @@ -17250,9 +17250,9 @@ namespace ts { } } - function checkGrammarNumericLiteral(node: Identifier): boolean { + function checkGrammarNumericLiteral(node: LiteralExpression): boolean { // Grammar checking - if (node.flags & NodeFlags.OctalLiteral && languageVersion >= ScriptTarget.ES5) { + if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) { return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a62739e1334..7e4b81db07a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1780,7 +1780,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write("]"); } else { - emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, + emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/ node.multiLine, /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); } } @@ -1803,7 +1803,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emitLinePreservingList(node, properties, /*allowTrailingComma*/ languageVersion >= ScriptTarget.ES5, /*spacesBetweenBraces*/ true); } else { - const multiLine = (node.flags & NodeFlags.MultiLine) !== 0; + const multiLine = node.multiLine; if (!multiLine) { write(" "); } @@ -1826,7 +1826,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) { - const multiLine = (node.flags & NodeFlags.MultiLine) !== 0; + const multiLine = node.multiLine; const properties = node.properties; write("("); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 787a022140f..4fd81ed246f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -666,8 +666,8 @@ namespace ts { sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = normalizePath(fileName); - sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0; sourceFile.languageVariant = getLanguageVariant(sourceFile.fileName); + sourceFile.isDeclarationFile = fileExtensionIs(sourceFile.fileName, ".d.ts"); return sourceFile; } @@ -1922,7 +1922,7 @@ namespace ts { && sourceText.charCodeAt(tokenPos) === CharacterCodes._0 && isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - node.flags |= NodeFlags.OctalLiteral; + node.isOctalLiteral = true; } return node; @@ -3907,7 +3907,9 @@ namespace ts { function parseArrayLiteralExpression(): ArrayLiteralExpression { const node = createNode(SyntaxKind.ArrayLiteralExpression); parseExpected(SyntaxKind.OpenBracketToken); - if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine; + if (scanner.hasPrecedingLineBreak()) { + node.multiLine = true; + } node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement); parseExpected(SyntaxKind.CloseBracketToken); return finishNode(node); @@ -3978,7 +3980,7 @@ namespace ts { const node = createNode(SyntaxKind.ObjectLiteralExpression); parseExpected(SyntaxKind.OpenBraceToken); if (scanner.hasPrecedingLineBreak()) { - node.flags |= NodeFlags.MultiLine; + node.multiLine = true; } node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimeter*/ true); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5cba4283857..4421a882121 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -381,12 +381,8 @@ namespace ts { Abstract = 1 << 7, // Class/Method/ConstructSignature Async = 1 << 8, // Property/Method/Function Default = 1 << 9, // Function/Class (export default declaration) - MultiLine = 1 << 10, // Multi-line array or object literal - Synthetic = 1 << 11, // Synthetic node (for full fidelity) - DeclarationFile = 1 << 12, // Node is a .d.ts file Let = 1 << 13, // Variable declaration Const = 1 << 14, // Variable declaration - OctalLiteral = 1 << 15, // Octal numeric literal Namespace = 1 << 16, // Namespace declaration ExportContext = 1 << 17, // Export context (initialized by binding) ContainsThis = 1 << 18, // Interface contains references to "this" @@ -938,6 +934,7 @@ namespace ts { text: string; isUnterminated?: boolean; hasExtendedUnicodeEscape?: boolean; + isOctalLiteral?: boolean; } // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, @@ -979,6 +976,7 @@ namespace ts { // @kind(SyntaxKind.ArrayLiteralExpression) export interface ArrayLiteralExpression extends PrimaryExpression { elements: NodeArray; + multiLine?: boolean; } // @kind(SyntaxKind.SpreadElementExpression) @@ -990,6 +988,7 @@ namespace ts { // @kind(SyntaxKind.ObjectLiteralExpression) export interface ObjectLiteralExpression extends PrimaryExpression, Declaration { properties: NodeArray; + multiLine?: boolean; } // @kind(SyntaxKind.PropertyAccessExpression) @@ -1546,6 +1545,7 @@ namespace ts { moduleName: string; referencedFiles: FileReference[]; languageVariant: LanguageVariant; + isDeclarationFile: boolean; // this map is used by transpiler to supply alternative names for dependencies (i.e. in case of bundling) /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bab66eb0688..7042200ba8e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -414,7 +414,7 @@ namespace ts { } export function isDeclarationFile(file: SourceFile): boolean { - return (file.flags & NodeFlags.DeclarationFile) !== 0; + return file.isDeclarationFile; } export function isConstEnumDeclaration(node: Node): boolean { @@ -1309,10 +1309,9 @@ namespace ts { export function isInAmbientContext(node: Node): boolean { while (node) { - if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) { + if (node.flags & NodeFlags.Ambient || (node.kind === SyntaxKind.SourceFile && (node as SourceFile).isDeclarationFile)) { return true; } - node = node.parent; } return false; diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index b7e909f69d8..4cd361734e3 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -10,7 +10,7 @@ namespace ts.BreakpointResolver { */ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number) { // Cannot set breakpoint in dts file - if (sourceFile.flags & NodeFlags.DeclarationFile) { + if (sourceFile.isDeclarationFile) { return undefined; } diff --git a/src/services/services.ts b/src/services/services.ts index cb57d415c66..bbc61a533b1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -237,14 +237,14 @@ namespace ts { while (pos < end) { const token = scanner.scan(); const textPos = scanner.getTextPos(); - nodes.push(createNode(token, pos, textPos, NodeFlags.Synthetic, this)); + nodes.push(createNode(token, pos, textPos, 0, this)); pos = textPos; } return pos; } private createSyntaxList(nodes: NodeArray): Node { - const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, NodeFlags.Synthetic, this); + const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, 0, this); list._children = []; let pos = nodes.pos; @@ -797,6 +797,7 @@ namespace ts { public parseDiagnostics: Diagnostic[]; public bindDiagnostics: Diagnostic[]; + public isDeclarationFile: boolean; public isDefaultLib: boolean; public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module