diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b8ddaedf67f..5ee4e053c5e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -14,18 +14,6 @@ module ts { return new (getNodeConstructor(kind))(); } - function isEvalOrArgumentsIdentifier(node: Node): boolean { - return node.kind === SyntaxKind.Identifier && - (node).text && - ((node).text === "eval" || (node).text === "arguments"); - } - - /// Should be called only on prologue directives (isPrologueDirective(node) should be true) - function isUseStrictPrologueDirective(node: Node): boolean { - Debug.assert(isPrologueDirective(node)); - return ((node).expression).text === "use strict"; - } - // Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes // stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, // embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns @@ -327,7 +315,9 @@ module ts { sys.writeFile(fileName, data, writeByteOrderMark); } catch (e) { - if (onError) onError(e.message); + if (onError) { + onError(e.message); + } } } @@ -433,6 +423,17 @@ module ts { forEachChild(sourceFile, walk); } + function isEvalOrArgumentsIdentifier(node: Node): boolean { + return node.kind === SyntaxKind.Identifier && + ((node).text === "eval" || (node).text === "arguments"); + } + + /// Should be called only on prologue directives (isPrologueDirective(node) should be true) + function isUseStrictPrologueDirective(node: Node): boolean { + Debug.assert(isPrologueDirective(node)); + return getTextOfNode((node).expression) === '"use strict"'; + } + export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false): SourceFile { var parsingContext: ParsingContext; var identifiers: Map = {}; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 15b0bdfc0b2..35e61a3a48e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -90,7 +90,9 @@ module ts { } export function getSourceFileOfNode(node: Node): SourceFile { - while (node && node.kind !== SyntaxKind.SourceFile) node = node.parent; + while (node && node.kind !== SyntaxKind.SourceFile) { + node = node.parent; + } return node; } @@ -161,7 +163,7 @@ module ts { node = getErrorSpanForNode(node); var file = getSourceFileOfNode(node); - var start = getFullWidth(node) === 0 ? node.pos : skipTrivia(file.text, node.pos); + var start = getTokenPosOfNode(node, file); var length = node.end - start; return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);