Merge branch 'master' into test262RunnerUpdates

This commit is contained in:
Mohamed Hegazy
2014-12-02 18:01:46 -08:00
66 changed files with 1025 additions and 182 deletions
+14 -17
View File
@@ -85,7 +85,6 @@ module ts {
getDiagnostics,
getDeclarationDiagnostics,
getGlobalDiagnostics,
checkProgram,
getParentOfSymbol,
getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol,
@@ -546,14 +545,18 @@ module ts {
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
}
function resolveExternalModuleName(location: Node, moduleExpression: Expression): Symbol {
if (moduleExpression.kind !== SyntaxKind.StringLiteral) {
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol {
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
return;
}
var moduleLiteral = <LiteralExpression>moduleExpression;
var moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
var searchPath = getDirectoryPath(getSourceFile(location).filename);
var moduleName = moduleLiteral.text;
// Module names are escaped in our symbol table. However, string literal values aren't.
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
var moduleName = escapeIdentifier(moduleReferenceLiteral.text);
if (!moduleName) return;
var isRelative = isExternalModuleNameRelative(moduleName);
if (!isRelative) {
@@ -574,10 +577,10 @@ module ts {
if (sourceFile.symbol) {
return getResolvedExportSymbol(sourceFile.symbol);
}
error(moduleLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.filename);
return;
}
error(moduleLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName);
}
function getResolvedExportSymbol(moduleSymbol: Symbol): Symbol {
@@ -8653,10 +8656,6 @@ module ts {
}
}
function checkProgram() {
forEach(program.getSourceFiles(), checkSourceFile);
}
function getSortedDiagnostics(): Diagnostic[]{
Debug.assert(fullTypeCheck, "diagnostics are available only in the full typecheck mode");
@@ -8669,12 +8668,11 @@ module ts {
}
function getDiagnostics(sourceFile?: SourceFile): Diagnostic[]{
if (sourceFile) {
checkSourceFile(sourceFile);
return filter(getSortedDiagnostics(), d => d.file === sourceFile);
}
checkProgram();
forEach(program.getSourceFiles(), checkSourceFile);
return getSortedDiagnostics();
}
@@ -9024,7 +9022,7 @@ module ts {
// This is necessary as an identifier in short-hand property assignment can contains two meaning:
// property name and property value.
if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) {
return resolveEntityName(location, (<ShortHandPropertyDeclaration>location).name, SymbolFlags.Value);
return resolveEntityName(location, (<ShorthandPropertyDeclaration>location).name, SymbolFlags.Value);
}
return undefined;
}
@@ -9192,9 +9190,9 @@ module ts {
return isImportResolvedToValue(getSymbolOfNode(node));
}
function hasSemanticErrors() {
function hasSemanticErrors(sourceFile?: SourceFile) {
// Return true if there is any semantic error in a file or globally
return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0;
return getDiagnostics(sourceFile).length > 0 || getGlobalDiagnostics().length > 0;
}
function isEmitBlocked(sourceFile?: SourceFile): boolean {
@@ -9312,7 +9310,6 @@ module ts {
function invokeEmitter(targetSourceFile?: SourceFile) {
var resolver = createResolver();
checkProgram();
return emitFiles(resolver, targetSourceFile);
}
+72 -38
View File
@@ -2236,33 +2236,35 @@ module ts {
emitTrailingComments(node);
}
function emitShortHandPropertyAssignment(node: ShortHandPropertyDeclaration) {
function emitAsNormalPropertyAssignment() {
emitLeadingComments(node);
// Emit identifier as an identifier
emit(node.name);
write(": ");
// Even though this is stored as identified because it is in short-hand property assignment,
// treated it as expression
emitExpressionIdentifier(node.name);
emitTrailingComments(node);
}
function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
emitLeadingComments(node);
// Emit identifier as an identifier
emit(node.name);
write(": ");
// Even though this is stored as identifier treat it as an expression
// Short-hand, { x }, is equivalent of normal form { x: x }
emitExpressionIdentifier(node.name);
emitTrailingComments(node);
}
if (compilerOptions.target < ScriptTarget.ES6) {
emitAsNormalPropertyAssignment();
function emitShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
// module m {
// export var y;
// }
// module m {
// export var obj = { y };
// }
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
var prefix = resolver.getExpressionNamePrefix(node.name);
if (prefix) {
emitDownlevelShorthandPropertyAssignment(node);
}
else if (compilerOptions.target >= ScriptTarget.ES6) {
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment
var prefix = resolver.getExpressionNamePrefix(node.name);
if (prefix) {
emitAsNormalPropertyAssignment();
}
// If short-hand property has no prefix, emit it as short-hand.
else {
emitLeadingComments(node);
emit(node.name);
emitTrailingComments(node);
}
// If short-hand property has no prefix, emit it as short-hand.
else {
emitLeadingComments(node);
emit(node.name);
emitTrailingComments(node);
}
}
@@ -3441,6 +3443,7 @@ module ts {
// Start new file on new line
writeLine();
emitDetachedComments(node);
// emit prologue directives prior to __extends
var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) {
@@ -3472,6 +3475,8 @@ module ts {
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
}
emitLeadingComments(node.endOfFileToken);
}
function emitNode(node: Node): void {
@@ -3483,6 +3488,7 @@ module ts {
return emitPinnedOrTripleSlashComments(node);
}
// Check if the node can be emitted regardless of the ScriptTarget
switch (node.kind) {
case SyntaxKind.Identifier:
return emitIdentifier(<Identifier>node);
@@ -3521,8 +3527,6 @@ module ts {
return emitObjectLiteral(<ObjectLiteralExpression>node);
case SyntaxKind.PropertyAssignment:
return emitPropertyAssignment(<PropertyDeclaration>node);
case SyntaxKind.ShorthandPropertyAssignment:
return emitShortHandPropertyAssignment(<ShortHandPropertyDeclaration>node);
case SyntaxKind.ComputedPropertyName:
return emitComputedPropertyName(<ComputedPropertyName>node);
case SyntaxKind.PropertyAccessExpression:
@@ -3618,6 +3622,23 @@ module ts {
case SyntaxKind.SourceFile:
return emitSourceFile(<SourceFile>node);
}
// Emit node which needs to be emitted differently depended on ScriptTarget
if (compilerOptions.target < ScriptTarget.ES6) {
// Emit node down-level
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitDownlevelShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
}
}
else {
// Emit node natively
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above");
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
}
}
}
function hasDetachedComments(pos: number) {
@@ -3791,20 +3812,14 @@ module ts {
}
}
var hasSemanticErrors = resolver.hasSemanticErrors();
var isEmitBlocked = resolver.isEmitBlocked(targetSourceFile);
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
if (!isEmitBlocked) {
emitJavaScript(jsFilePath, sourceFile);
if (!hasSemanticErrors && compilerOptions.declaration) {
writeDeclarationFile(jsFilePath, sourceFile);
}
}
}
var hasSemanticErrors: boolean = false;
var isEmitBlocked: boolean = false;
if (targetSourceFile === undefined) {
// No targetSourceFile is specified (e.g. calling emitter from batch compiler)
hasSemanticErrors = resolver.hasSemanticErrors();
isEmitBlocked = resolver.isEmitBlocked();
forEach(program.getSourceFiles(), sourceFile => {
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, program, ".js");
@@ -3820,16 +3835,35 @@ module ts {
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
// If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
hasSemanticErrors = resolver.hasSemanticErrors(targetSourceFile);
isEmitBlocked = resolver.isEmitBlocked(targetSourceFile);
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
emitFile(jsFilePath, targetSourceFile);
}
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
// Otherwise, if --out is specified and targetSourceFile is not a declaration file,
// Emit all, non-external-module file, into one single output file
forEach(program.getSourceFiles(), sourceFile => {
if (!shouldEmitToOwnFile(sourceFile, compilerOptions)) {
hasSemanticErrors = hasSemanticErrors || resolver.hasSemanticErrors(sourceFile);
isEmitBlocked = isEmitBlocked || resolver.isEmitBlocked(sourceFile);
}
});
emitFile(compilerOptions.out);
}
}
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
if (!isEmitBlocked) {
emitJavaScript(jsFilePath, sourceFile);
if (!hasSemanticErrors && compilerOptions.declaration) {
writeDeclarationFile(jsFilePath, sourceFile);
}
}
}
// Sort and make the unique list of diagnostics
diagnostics.sort(compareDiagnostics);
diagnostics = deduplicateSortedDiagnostics(diagnostics);
+69 -54
View File
@@ -313,8 +313,10 @@ module ts {
case SyntaxKind.FinallyBlock:
case SyntaxKind.FunctionBlock:
case SyntaxKind.ModuleBlock:
case SyntaxKind.SourceFile:
return children((<Block>node).statements);
case SyntaxKind.SourceFile:
return children((<SourceFile>node).statements) ||
child((<SourceFile>node).endOfFileToken);
case SyntaxKind.VariableStatement:
return children(node.modifiers) ||
children((<VariableStatement>node).declarations);
@@ -943,7 +945,6 @@ module ts {
}
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile {
var file: SourceFile;
var scanner: Scanner;
var token: SyntaxKind;
var parsingContext: ParsingContext;
@@ -1101,22 +1102,22 @@ module ts {
return getPositionFromLineAndCharacter(getLineStarts(), line, character);
}
function error(message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var start = scanner.getTokenPos();
var length = scanner.getTextPos() - start;
errorAtPosition(start, length, message, arg0, arg1, arg2);
parseErrorAtPosition(start, length, message, arg0, arg1, arg2);
}
function errorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var lastErrorPosition = file.parseDiagnostics.length
? file.parseDiagnostics[file.parseDiagnostics.length - 1].start
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void {
var lastErrorPosition = sourceFile.parseDiagnostics.length
? sourceFile.parseDiagnostics[sourceFile.parseDiagnostics.length - 1].start
: -1;
// Don't report another error if it would just be at the same position as the last error.
if (start !== lastErrorPosition) {
var diagnostic = createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
file.parseDiagnostics.push(diagnostic);
var diagnostic = createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2);
sourceFile.parseDiagnostics.push(diagnostic);
}
if (lookAheadMode === LookAheadMode.NoErrorYet) {
@@ -1126,7 +1127,7 @@ module ts {
function scanError(message: DiagnosticMessage) {
var pos = scanner.getTextPos();
errorAtPosition(pos, 0, message);
parseErrorAtPosition(pos, 0, message);
}
function onComment(pos: number, end: number) {
@@ -1165,7 +1166,7 @@ module ts {
// Keep track of the state we'll need to rollback to if lookahead fails (or if the
// caller asked us to always reset our state).
var saveToken = token;
var saveSyntacticErrorsLength = file.parseDiagnostics.length;
var saveSyntacticErrorsLength = sourceFile.parseDiagnostics.length;
// Keep track of the current look ahead mode (this matters if we have nested
// speculative parsing).
@@ -1187,7 +1188,7 @@ module ts {
lookAheadMode = saveLookAheadMode;
if (!result || alwaysResetState) {
token = saveToken;
file.parseDiagnostics.length = saveSyntacticErrorsLength;
sourceFile.parseDiagnostics.length = saveSyntacticErrorsLength;
}
return result;
@@ -1236,10 +1237,10 @@ module ts {
// Report specific message if provided with one. Otherwise, report generic fallback message.
if (diagnosticMessage) {
error(diagnosticMessage, arg0);
parseErrorAtCurrentToken(diagnosticMessage, arg0);
}
else {
error(Diagnostics._0_expected, tokenToString(kind));
parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind));
}
return false;
}
@@ -1307,10 +1308,10 @@ module ts {
function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node {
if (reportAtCurrentPosition) {
errorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
}
else {
error(diagnosticMessage, arg0);
parseErrorAtCurrentToken(diagnosticMessage, arg0);
}
return createMissingNodeWithoutError(kind);
@@ -1395,10 +1396,12 @@ module ts {
}
function parseContextualModifier(t: SyntaxKind): boolean {
return token === t && tryParse(() => {
nextToken();
return canFollowModifier();
});
return token === t && tryParse(nextTokenCanFollowModifier);
}
function nextTokenCanFollowModifier() {
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier(): boolean {
@@ -1599,7 +1602,7 @@ module ts {
// Returns true if we should abort parsing.
function abortParsingListOrMoveToNextToken(kind: ParsingContext) {
error(parsingContextErrors(kind));
parseErrorAtCurrentToken(parsingContextErrors(kind));
if (isInSomeParsingContext()) {
return true;
}
@@ -3188,7 +3191,7 @@ module ts {
// Parse to check if it is short-hand property assignment or normal property assignment
if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) {
var shorthandDeclaration = <ShortHandPropertyDeclaration>createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos);
var shorthandDeclaration = <ShorthandPropertyDeclaration>createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos);
shorthandDeclaration.name = <Identifier>propertyName;
shorthandDeclaration.questionToken = questionToken;
return finishNode(shorthandDeclaration);
@@ -4066,9 +4069,13 @@ module ts {
// literals. We check to ensure that it is only a string literal later in the grammar
// walker.
node.expression = parseExpression();
// Ensure the string being required is in our 'identifier' table. This will ensure
// that features like 'find refs' will look inside this file when search for its name.
if (node.expression.kind === SyntaxKind.StringLiteral) {
internIdentifier((<LiteralExpression>node.expression).text);
}
parseExpected(SyntaxKind.CloseParenToken);
return finishNode(node);
}
@@ -4200,13 +4207,13 @@ module ts {
var referencePathMatchResult = getFileReferenceFromReferencePath(comment, range);
if (referencePathMatchResult) {
var fileReference = referencePathMatchResult.fileReference;
file.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
sourceFile.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
var diagnosticMessage = referencePathMatchResult.diagnosticMessage;
if (fileReference) {
referencedFiles.push(fileReference);
}
if (diagnosticMessage) {
file.parseDiagnostics.push(createFileDiagnostic(file, range.pos, range.end - range.pos, diagnosticMessage));
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
}
}
else {
@@ -4214,7 +4221,7 @@ module ts {
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
if(amdModuleNameMatchResult) {
if(amdModuleName) {
file.parseDiagnostics.push(createFileDiagnostic(file, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
sourceFile.referenceDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
}
amdModuleName = amdModuleNameMatchResult[2];
}
@@ -4235,7 +4242,7 @@ module ts {
}
function getExternalModuleIndicator() {
return forEach(file.statements, node =>
return forEach(sourceFile.statements, node =>
node.flags & NodeFlags.Export
|| node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference
|| node.kind === SyntaxKind.ExportAssignment
@@ -4246,15 +4253,15 @@ module ts {
var syntacticDiagnostics: Diagnostic[];
function getSyntacticDiagnostics() {
if (syntacticDiagnostics === undefined) {
if (file.parseDiagnostics.length > 0) {
if (sourceFile.parseDiagnostics.length > 0) {
// Don't bother doing any grammar checks if there are already parser errors.
// Otherwise we may end up with too many cascading errors.
syntacticDiagnostics = file.parseDiagnostics;
syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics);
}
else {
// No parser errors were reported. Perform our stricter grammar checks.
syntacticDiagnostics = file.grammarDiagnostics;
checkGrammar(sourceText, languageVersion, file);
checkGrammar(sourceText, languageVersion, sourceFile);
syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.grammarDiagnostics);
}
}
@@ -4267,32 +4274,40 @@ module ts {
if (fileExtensionIs(filename, ".d.ts")) {
rootNodeFlags = NodeFlags.DeclarationFile;
}
file = <SourceFile>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags);
file.filename = normalizePath(filename);
file.text = sourceText;
file.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
file.getLineStarts = getLineStarts;
file.getSyntacticDiagnostics = getSyntacticDiagnostics;
file.parseDiagnostics = [];
file.grammarDiagnostics = [];
file.semanticDiagnostics = [];
var sourceFile = <SourceFile>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags);
sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
sourceFile.getLineStarts = getLineStarts;
sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics;
sourceFile.filename = normalizePath(filename);
sourceFile.text = sourceText;
sourceFile.referenceDiagnostics = [];
sourceFile.parseDiagnostics = [];
sourceFile.grammarDiagnostics = [];
sourceFile.semanticDiagnostics = [];
var referenceComments = processReferenceComments();
file.referencedFiles = referenceComments.referencedFiles;
file.amdDependencies = referenceComments.amdDependencies;
file.amdModuleName = referenceComments.amdModuleName;
sourceFile.referencedFiles = referenceComments.referencedFiles;
sourceFile.amdDependencies = referenceComments.amdDependencies;
sourceFile.amdModuleName = referenceComments.amdModuleName;
file.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
file.externalModuleIndicator = getExternalModuleIndicator();
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
Debug.assert(token === SyntaxKind.EndOfFileToken);
sourceFile.endOfFileToken = parseTokenNode();
file.nodeCount = nodeCount;
file.identifierCount = identifierCount;
file.version = version;
file.isOpen = isOpen;
file.languageVersion = languageVersion;
file.identifiers = identifiers;
return file;
sourceFile.externalModuleIndicator = getExternalModuleIndicator();
sourceFile.nodeCount = nodeCount;
sourceFile.identifierCount = identifierCount;
sourceFile.version = version;
sourceFile.isOpen = isOpen;
sourceFile.languageVersion = languageVersion;
sourceFile.identifiers = identifiers;
return sourceFile;
}
function isLeftHandSideExpression(expr: Expression): boolean {
@@ -4432,7 +4447,7 @@ module ts {
case SyntaxKind.ReturnStatement: return checkReturnStatement(<ReturnStatement>node);
case SyntaxKind.SetAccessor: return checkSetAccessor(<MethodDeclaration>node);
case SyntaxKind.SourceFile: return checkSourceFile(<SourceFile>node);
case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(<ShortHandPropertyDeclaration>node);
case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);
case SyntaxKind.SwitchStatement: return checkSwitchStatement(<SwitchStatement>node);
case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(<TaggedTemplateExpression>node);
case SyntaxKind.ThrowStatement: return checkThrowStatement(<ThrowStatement>node);
@@ -5449,7 +5464,7 @@ module ts {
return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
}
function checkShorthandPropertyAssignment(node: ShortHandPropertyDeclaration): boolean {
function checkShorthandPropertyAssignment(node: ShorthandPropertyDeclaration): boolean {
return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
}
+16 -9
View File
@@ -257,7 +257,7 @@ module ts {
LastTypeNode = ParenthesizedType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = EndOfFileToken,
FirstToken = Unknown,
LastToken = TypeKeyword,
FirstTriviaToken = SingleLineCommentTrivia,
LastTriviaToken = WhitespaceTrivia,
@@ -386,7 +386,7 @@ module ts {
export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration;
export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration;
export interface ShortHandPropertyDeclaration extends Declaration {
export interface ShorthandPropertyDeclaration extends Declaration {
name: Identifier;
questionToken?: Node;
}
@@ -786,6 +786,7 @@ module ts {
// Source files are declarations when they are external modules.
export interface SourceFile extends Declaration {
statements: NodeArray<ModuleElement>;
endOfFileToken: Node;
filename: string;
text: string;
@@ -795,17 +796,24 @@ module ts {
amdDependencies: string[];
amdModuleName: string;
referencedFiles: FileReference[];
semanticDiagnostics: Diagnostic[];
// Diagnostics reported about the "///<reference" comments in the file.
referenceDiagnostics: Diagnostic[];
// Parse errors refer specifically to things the parser could not understand at all (like
// missing tokens, or tokens it didn't know how to deal with). Grammar errors are for
// things the parser understood, but either the ES6 or TS grammars do not allow (like
// putting an 'public' modifier on a 'class declaration').
// missing tokens, or tokens it didn't know how to deal with).
parseDiagnostics: Diagnostic[];
// Grammar errors are for things the parser understood, but either the ES6 or TS grammars
// do not allow (like putting an 'public' modifier on a 'class declaration').
grammarDiagnostics: Diagnostic[];
// Returns all
// Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics).
getSyntacticDiagnostics(): Diagnostic[];
// File level diagnostics reported by the binder.
semanticDiagnostics: Diagnostic[];
hasNoDefaultLib: boolean;
externalModuleIndicator: Node; // The first node that causes this file to be an external module
nodeCount: number;
@@ -874,7 +882,6 @@ module ts {
getIdentifierCount(): number;
getSymbolCount(): number;
getTypeCount(): number;
checkProgram(): void;
emitFiles(targetSourceFile?: SourceFile): EmitResult;
getParentOfSymbol(symbol: Symbol): Symbol;
getNarrowedTypeOfSymbol(symbol: Symbol, node: Node): Type;
@@ -986,7 +993,7 @@ module ts {
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
getNodeCheckFlags(node: Node): NodeCheckFlags;
getEnumMemberValue(node: EnumMember): number;
hasSemanticErrors(): boolean;
hasSemanticErrors(sourceFile?: SourceFile): boolean;
isDeclarationVisible(node: Declaration): boolean;
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableOrParameterDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
+3 -4
View File
@@ -2217,11 +2217,10 @@ module FourSlash {
// TODO (drosen): We need to enforce checking on these tests.
var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js", noResolve: true }, host);
var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true);
checker.checkProgram();
var errs = program.getDiagnostics().concat(checker.getDiagnostics());
if (errs.length > 0) {
throw new Error('Error compiling ' + fileName + ': ' + errs.map(e => e.messageText).join('\r\n'));
var errors = program.getDiagnostics().concat(checker.getDiagnostics());
if (errors.length > 0) {
throw new Error('Error compiling ' + fileName + ': ' + errors.map(e => e.messageText).join('\r\n'));
}
checker.emitFiles();
result = result || ''; // Might have an empty fourslash file
-1
View File
@@ -801,7 +801,6 @@ module Harness {
useCaseSensitiveFileNames));
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
checker.checkProgram();
var isEmitBlocked = checker.isEmitBlocked();
+17 -42
View File
@@ -722,6 +722,9 @@ module ts {
public filename: string;
public text: string;
public statements: NodeArray<Statement>;
public endOfFileToken: Node;
// These methods will have their implementation provided by the implementation the
// compiler actually exports off of SourceFile.
public getLineAndCharacterFromPosition: (position: number) => LineAndCharacter;
@@ -732,15 +735,17 @@ module ts {
public amdDependencies: string[];
public amdModuleName: string;
public referencedFiles: FileReference[];
public referenceDiagnostics: Diagnostic[];
public parseDiagnostics: Diagnostic[];
public grammarDiagnostics: Diagnostic[];
public semanticDiagnostics: Diagnostic[];
public hasNoDefaultLib: boolean;
public externalModuleIndicator: Node; // The first node that causes this file to be an external module
public nodeCount: number;
public identifierCount: number;
public symbolCount: number;
public statements: NodeArray<Statement>;
public version: string;
public isOpen: boolean;
public languageVersion: ScriptTarget;
@@ -4665,18 +4670,14 @@ module ts {
function getEmitOutput(filename: string): EmitOutput {
synchronizeHostData();
filename = normalizeSlashes(filename);
var compilerOptions = program.getCompilerOptions();
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
var emitOutput: EmitOutput = {
outputFiles: [],
emitOutputStatus: undefined,
};
var sourceFile = getSourceFile(filename);
var outputFiles: OutputFile[] = [];
function getEmitOutputWriter(filename: string, data: string, writeByteOrderMark: boolean) {
emitOutput.outputFiles.push({
outputFiles.push({
name: filename,
writeByteOrderMark: writeByteOrderMark,
text: data
@@ -4686,41 +4687,15 @@ module ts {
// Initialize writer for CompilerHost.writeFile
writer = getEmitOutputWriter;
var containSyntacticErrors = false;
if (shouldEmitToOwnFile) {
// Check only the file we want to emit
containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile));
} else {
// Check the syntactic of only sourceFiles that will get emitted into single output
// Terminate the process immediately if we encounter a syntax error from one of the sourceFiles
containSyntacticErrors = forEach(program.getSourceFiles(), sourceFile => {
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
// If emit to a single file then we will check all files that do not have external module
return containErrors(program.getDiagnostics(sourceFile));
}
return false;
});
}
if (containSyntacticErrors) {
// If there is a syntax error, terminate the process and report outputStatus
emitOutput.emitOutputStatus = EmitReturnStatus.AllOutputGenerationSkipped;
// Reset writer back to undefined to make sure that we produce an error message
// if CompilerHost.writeFile is called when we are not in getEmitOutput
writer = undefined;
return emitOutput;
}
// Perform semantic and force a type check before emit to ensure that all symbols are updated
// EmitFiles will report if there is an error from TypeChecker and Emitter
// Depend whether we will have to emit into a single file or not either emit only selected file in the project, emit all files into a single file
var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
var emitOutput = getFullTypeCheckChecker().emitFiles(sourceFile);
// Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput
writer = undefined;
return emitOutput;
return {
outputFiles,
emitOutputStatus: emitOutput.emitResultStatus
};
}
function getMeaningFromDeclaration(node: Node): SemanticMeaning {
+7 -1
View File
@@ -912,6 +912,13 @@ module ts {
throw new Error("Invalid operation");
}
}
// Here we expose the TypeScript services as an external module
// so that it may be consumed easily like a node module.
declare var module: any;
if (typeof module !== "undefined" && module.exports) {
module.exports = ts;
}
}
@@ -919,4 +926,3 @@ module ts {
module TypeScript.Services {
export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory;
}
-4
View File
@@ -280,10 +280,6 @@ module ts {
}
function nodeHasTokens(n: Node): boolean {
if (n.kind === SyntaxKind.Unknown) {
return false;
}
// If we have a token or node that has a non-zero width, it must have tokens.
// Note, that getWidth() does not take trivia into account.
return n.getWidth() !== 0;