merge with master
This commit is contained in:
commit
f3e03dbec7
28 changed files with 413 additions and 112 deletions
|
@ -37,6 +37,11 @@
|
||||||
"tslint": "latest"
|
"tslint": "latest"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jake runtests"
|
"pretest": "jake tests",
|
||||||
|
"test": "jake runtests",
|
||||||
|
"build": "npm run build:compiler && npm run build:tests",
|
||||||
|
"build:compiler": "jake local",
|
||||||
|
"build:tests": "jake tests",
|
||||||
|
"clean": "jake clean"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6436,6 +6436,39 @@ namespace ts {
|
||||||
let classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
|
let classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
|
||||||
let baseClassType = classType && getBaseTypes(classType)[0];
|
let baseClassType = classType && getBaseTypes(classType)[0];
|
||||||
|
|
||||||
|
let container = getSuperContainer(node, /*includeFunctions*/ true);
|
||||||
|
let needToCaptureLexicalThis = false;
|
||||||
|
|
||||||
|
if (!isCallExpression) {
|
||||||
|
// adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting
|
||||||
|
while (container && container.kind === SyntaxKind.ArrowFunction) {
|
||||||
|
container = getSuperContainer(container, /*includeFunctions*/ true);
|
||||||
|
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let canUseSuperExpression = isLegalUsageOfSuperExpression(container);
|
||||||
|
let nodeCheckFlag: NodeCheckFlags = 0;
|
||||||
|
|
||||||
|
// always set NodeCheckFlags for 'super' expression node
|
||||||
|
if (canUseSuperExpression) {
|
||||||
|
if ((container.flags & NodeFlags.Static) || isCallExpression) {
|
||||||
|
nodeCheckFlag = NodeCheckFlags.SuperStatic;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nodeCheckFlag = NodeCheckFlags.SuperInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
getNodeLinks(node).flags |= nodeCheckFlag;
|
||||||
|
|
||||||
|
if (needToCaptureLexicalThis) {
|
||||||
|
// call expressions are allowed only in constructors so they should always capture correct 'this'
|
||||||
|
// super property access expressions can also appear in arrow functions -
|
||||||
|
// in this case they should also use correct lexical this
|
||||||
|
captureLexicalThis(node.parent, container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!baseClassType) {
|
if (!baseClassType) {
|
||||||
if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) {
|
if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) {
|
||||||
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
|
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
|
||||||
|
@ -6443,80 +6476,7 @@ namespace ts {
|
||||||
return unknownType;
|
return unknownType;
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = getSuperContainer(node, /*includeFunctions*/ true);
|
if (!canUseSuperExpression) {
|
||||||
|
|
||||||
if (container) {
|
|
||||||
let canUseSuperExpression = false;
|
|
||||||
let needToCaptureLexicalThis: boolean;
|
|
||||||
if (isCallExpression) {
|
|
||||||
// TS 1.0 SPEC (April 2014): 4.8.1
|
|
||||||
// Super calls are only permitted in constructors of derived classes
|
|
||||||
canUseSuperExpression = container.kind === SyntaxKind.Constructor;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// TS 1.0 SPEC (April 2014)
|
|
||||||
// 'super' property access is allowed
|
|
||||||
// - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance
|
|
||||||
// - In a static member function or static member accessor
|
|
||||||
|
|
||||||
// super property access might appear in arrow functions with arbitrary deep nesting
|
|
||||||
needToCaptureLexicalThis = false;
|
|
||||||
while (container && container.kind === SyntaxKind.ArrowFunction) {
|
|
||||||
container = getSuperContainer(container, /*includeFunctions*/ true);
|
|
||||||
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// topmost container must be something that is directly nested in the class declaration
|
|
||||||
if (container && isClassLike(container.parent)) {
|
|
||||||
if (container.flags & NodeFlags.Static) {
|
|
||||||
canUseSuperExpression =
|
|
||||||
container.kind === SyntaxKind.MethodDeclaration ||
|
|
||||||
container.kind === SyntaxKind.MethodSignature ||
|
|
||||||
container.kind === SyntaxKind.GetAccessor ||
|
|
||||||
container.kind === SyntaxKind.SetAccessor;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
canUseSuperExpression =
|
|
||||||
container.kind === SyntaxKind.MethodDeclaration ||
|
|
||||||
container.kind === SyntaxKind.MethodSignature ||
|
|
||||||
container.kind === SyntaxKind.GetAccessor ||
|
|
||||||
container.kind === SyntaxKind.SetAccessor ||
|
|
||||||
container.kind === SyntaxKind.PropertyDeclaration ||
|
|
||||||
container.kind === SyntaxKind.PropertySignature ||
|
|
||||||
container.kind === SyntaxKind.Constructor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canUseSuperExpression) {
|
|
||||||
let returnType: Type;
|
|
||||||
|
|
||||||
if ((container.flags & NodeFlags.Static) || isCallExpression) {
|
|
||||||
getNodeLinks(node).flags |= NodeCheckFlags.SuperStatic;
|
|
||||||
returnType = getBaseConstructorTypeOfClass(classType);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
getNodeLinks(node).flags |= NodeCheckFlags.SuperInstance;
|
|
||||||
returnType = baseClassType;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (container.kind === SyntaxKind.Constructor && isInConstructorArgumentInitializer(node, container)) {
|
|
||||||
// issue custom error message for super property access in constructor arguments (to be aligned with old compiler)
|
|
||||||
error(node, Diagnostics.super_cannot_be_referenced_in_constructor_arguments);
|
|
||||||
returnType = unknownType;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isCallExpression && needToCaptureLexicalThis) {
|
|
||||||
// call expressions are allowed only in constructors so they should always capture correct 'this'
|
|
||||||
// super property access expressions can also appear in arrow functions -
|
|
||||||
// in this case they should also use correct lexical this
|
|
||||||
captureLexicalThis(node.parent, container);
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
|
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
|
||||||
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
|
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
|
||||||
}
|
}
|
||||||
|
@ -6530,6 +6490,56 @@ namespace ts {
|
||||||
return unknownType;
|
return unknownType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (container.kind === SyntaxKind.Constructor && isInConstructorArgumentInitializer(node, container)) {
|
||||||
|
// issue custom error message for super property access in constructor arguments (to be aligned with old compiler)
|
||||||
|
error(node, Diagnostics.super_cannot_be_referenced_in_constructor_arguments);
|
||||||
|
return unknownType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeCheckFlag === NodeCheckFlags.SuperStatic
|
||||||
|
? getBaseConstructorTypeOfClass(classType)
|
||||||
|
: baseClassType;
|
||||||
|
|
||||||
|
function isLegalUsageOfSuperExpression(container: Node): boolean {
|
||||||
|
if (!container) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCallExpression) {
|
||||||
|
// TS 1.0 SPEC (April 2014): 4.8.1
|
||||||
|
// Super calls are only permitted in constructors of derived classes
|
||||||
|
return container.kind === SyntaxKind.Constructor;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TS 1.0 SPEC (April 2014)
|
||||||
|
// 'super' property access is allowed
|
||||||
|
// - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance
|
||||||
|
// - In a static member function or static member accessor
|
||||||
|
|
||||||
|
// topmost container must be something that is directly nested in the class declaration
|
||||||
|
if (container && isClassLike(container.parent)) {
|
||||||
|
if (container.flags & NodeFlags.Static) {
|
||||||
|
return container.kind === SyntaxKind.MethodDeclaration ||
|
||||||
|
container.kind === SyntaxKind.MethodSignature ||
|
||||||
|
container.kind === SyntaxKind.GetAccessor ||
|
||||||
|
container.kind === SyntaxKind.SetAccessor;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return container.kind === SyntaxKind.MethodDeclaration ||
|
||||||
|
container.kind === SyntaxKind.MethodSignature ||
|
||||||
|
container.kind === SyntaxKind.GetAccessor ||
|
||||||
|
container.kind === SyntaxKind.SetAccessor ||
|
||||||
|
container.kind === SyntaxKind.PropertyDeclaration ||
|
||||||
|
container.kind === SyntaxKind.PropertySignature ||
|
||||||
|
container.kind === SyntaxKind.Constructor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return contextual type of parameter or undefined if no contextual type is available
|
// Return contextual type of parameter or undefined if no contextual type is available
|
||||||
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
|
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
|
||||||
if (isFunctionExpressionOrArrowFunction(parameter.parent)) {
|
if (isFunctionExpressionOrArrowFunction(parameter.parent)) {
|
||||||
|
|
|
@ -6259,6 +6259,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
write(`], function(${exportFunctionForFile}) {`);
|
write(`], function(${exportFunctionForFile}) {`);
|
||||||
writeLine();
|
writeLine();
|
||||||
increaseIndent();
|
increaseIndent();
|
||||||
|
emitEmitHelpers(node);
|
||||||
emitCaptureThisForNodeIfNecessary(node);
|
emitCaptureThisForNodeIfNecessary(node);
|
||||||
emitSystemModuleBody(node, startIndex);
|
emitSystemModuleBody(node, startIndex);
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
|
@ -6330,6 +6331,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitAMDModule(node: SourceFile, startIndex: number) {
|
function emitAMDModule(node: SourceFile, startIndex: number) {
|
||||||
|
emitEmitHelpers(node);
|
||||||
collectExternalModuleInfo(node);
|
collectExternalModuleInfo(node);
|
||||||
|
|
||||||
writeLine();
|
writeLine();
|
||||||
|
@ -6351,6 +6353,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitCommonJSModule(node: SourceFile, startIndex: number) {
|
function emitCommonJSModule(node: SourceFile, startIndex: number) {
|
||||||
|
emitEmitHelpers(node);
|
||||||
collectExternalModuleInfo(node);
|
collectExternalModuleInfo(node);
|
||||||
emitExportStarHelper();
|
emitExportStarHelper();
|
||||||
emitCaptureThisForNodeIfNecessary(node);
|
emitCaptureThisForNodeIfNecessary(node);
|
||||||
|
@ -6360,6 +6363,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitUMDModule(node: SourceFile, startIndex: number) {
|
function emitUMDModule(node: SourceFile, startIndex: number) {
|
||||||
|
emitEmitHelpers(node);
|
||||||
collectExternalModuleInfo(node);
|
collectExternalModuleInfo(node);
|
||||||
|
|
||||||
// Module is detected first to support Browserify users that load into a browser with an AMD loader
|
// Module is detected first to support Browserify users that load into a browser with an AMD loader
|
||||||
|
@ -6389,6 +6393,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
exportSpecifiers = undefined;
|
exportSpecifiers = undefined;
|
||||||
exportEquals = undefined;
|
exportEquals = undefined;
|
||||||
hasExportStars = false;
|
hasExportStars = false;
|
||||||
|
emitEmitHelpers(node);
|
||||||
emitCaptureThisForNodeIfNecessary(node);
|
emitCaptureThisForNodeIfNecessary(node);
|
||||||
emitLinesStartingAt(node.statements, startIndex);
|
emitLinesStartingAt(node.statements, startIndex);
|
||||||
emitTempDeclarations(/*newLine*/ true);
|
emitTempDeclarations(/*newLine*/ true);
|
||||||
|
@ -6527,14 +6532,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitSourceFileNode(node: SourceFile) {
|
function emitEmitHelpers(node: SourceFile): void {
|
||||||
// Start new file on new line
|
|
||||||
writeLine();
|
|
||||||
emitDetachedComments(node);
|
|
||||||
|
|
||||||
// emit prologue directives prior to __extends
|
|
||||||
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
|
|
||||||
|
|
||||||
// Only emit helpers if the user did not say otherwise.
|
// Only emit helpers if the user did not say otherwise.
|
||||||
if (!compilerOptions.noEmitHelpers) {
|
if (!compilerOptions.noEmitHelpers) {
|
||||||
// Only Emit __extends function when target ES5.
|
// Only Emit __extends function when target ES5.
|
||||||
|
@ -6562,6 +6560,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
awaiterEmitted = true;
|
awaiterEmitted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitSourceFileNode(node: SourceFile) {
|
||||||
|
// Start new file on new line
|
||||||
|
writeLine();
|
||||||
|
emitShebang();
|
||||||
|
emitDetachedComments(node);
|
||||||
|
|
||||||
|
// emit prologue directives prior to __extends
|
||||||
|
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
|
||||||
|
|
||||||
if (isExternalModule(node) || compilerOptions.isolatedModules) {
|
if (isExternalModule(node) || compilerOptions.isolatedModules) {
|
||||||
if (languageVersion >= ScriptTarget.ES6) {
|
if (languageVersion >= ScriptTarget.ES6) {
|
||||||
|
@ -6585,6 +6593,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
exportSpecifiers = undefined;
|
exportSpecifiers = undefined;
|
||||||
exportEquals = undefined;
|
exportEquals = undefined;
|
||||||
hasExportStars = false;
|
hasExportStars = false;
|
||||||
|
emitEmitHelpers(node);
|
||||||
emitCaptureThisForNodeIfNecessary(node);
|
emitCaptureThisForNodeIfNecessary(node);
|
||||||
emitLinesStartingAt(node.statements, startIndex);
|
emitLinesStartingAt(node.statements, startIndex);
|
||||||
emitTempDeclarations(/*newLine*/ true);
|
emitTempDeclarations(/*newLine*/ true);
|
||||||
|
@ -6979,6 +6988,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function emitShebang() {
|
||||||
|
let shebang = getShebang(currentSourceFile.text);
|
||||||
|
if (shebang) {
|
||||||
|
write(shebang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function isPinnedOrTripleSlashComment(comment: CommentRange) {
|
function isPinnedOrTripleSlashComment(comment: CommentRange) {
|
||||||
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
|
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
|
||||||
return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation;
|
return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation;
|
||||||
|
|
|
@ -408,6 +408,9 @@ namespace ts {
|
||||||
case CharacterCodes.greaterThan:
|
case CharacterCodes.greaterThan:
|
||||||
// Starts of conflict marker trivia
|
// Starts of conflict marker trivia
|
||||||
return true;
|
return true;
|
||||||
|
case CharacterCodes.hash:
|
||||||
|
// Only if its the beginning can we have #! trivia
|
||||||
|
return pos === 0;
|
||||||
default:
|
default:
|
||||||
return ch > CharacterCodes.maxAsciiCharacter;
|
return ch > CharacterCodes.maxAsciiCharacter;
|
||||||
}
|
}
|
||||||
|
@ -468,6 +471,13 @@ namespace ts {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CharacterCodes.hash:
|
||||||
|
if (isShebangTrivia(text, pos)) {
|
||||||
|
pos = scanShebangTrivia(text, pos);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) {
|
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) {
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -535,6 +545,20 @@ namespace ts {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shebangTriviaRegex = /^#!.*/;
|
||||||
|
|
||||||
|
function isShebangTrivia(text: string, pos: number) {
|
||||||
|
// Shebangs check must only be done at the start of the file
|
||||||
|
Debug.assert(pos === 0);
|
||||||
|
return shebangTriviaRegex.test(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function scanShebangTrivia(text: string, pos: number) {
|
||||||
|
let shebang = shebangTriviaRegex.exec(text)[0];
|
||||||
|
pos = pos + shebang.length;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract comments from text prefixing the token closest following `pos`.
|
* Extract comments from text prefixing the token closest following `pos`.
|
||||||
* The return value is an array containing a TextRange for each comment.
|
* The return value is an array containing a TextRange for each comment.
|
||||||
|
@ -629,6 +653,13 @@ namespace ts {
|
||||||
return getCommentRanges(text, pos, /*trailing*/ true);
|
return getCommentRanges(text, pos, /*trailing*/ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Optionally, get the shebang */
|
||||||
|
export function getShebang(text: string): string {
|
||||||
|
return shebangTriviaRegex.test(text)
|
||||||
|
? shebangTriviaRegex.exec(text)[0]
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean {
|
export function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean {
|
||||||
return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z ||
|
return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z ||
|
||||||
ch === CharacterCodes.$ || ch === CharacterCodes._ ||
|
ch === CharacterCodes.$ || ch === CharacterCodes._ ||
|
||||||
|
@ -1098,6 +1129,18 @@ namespace ts {
|
||||||
return token = SyntaxKind.EndOfFileToken;
|
return token = SyntaxKind.EndOfFileToken;
|
||||||
}
|
}
|
||||||
let ch = text.charCodeAt(pos);
|
let ch = text.charCodeAt(pos);
|
||||||
|
|
||||||
|
// Special handling for shebang
|
||||||
|
if (ch === CharacterCodes.hash && pos === 0 && isShebangTrivia(text, pos)) {
|
||||||
|
pos = scanShebangTrivia(text ,pos);
|
||||||
|
if (skipTrivia) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return token = SyntaxKind.ShebangTrivia;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case CharacterCodes.lineFeed:
|
case CharacterCodes.lineFeed:
|
||||||
case CharacterCodes.carriageReturn:
|
case CharacterCodes.carriageReturn:
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace ts {
|
||||||
let matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
|
let matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
|
||||||
|
|
||||||
if (!matchResult) {
|
if (!matchResult) {
|
||||||
errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, 'en', 'ja-jp'));
|
errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, "en", "ja-jp"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add codePage support for readFile?
|
// TODO: Add codePage support for readFile?
|
||||||
let fileContents = '';
|
let fileContents = "";
|
||||||
try {
|
try {
|
||||||
fileContents = sys.readFile(filePath);
|
fileContents = sys.readFile(filePath);
|
||||||
}
|
}
|
||||||
|
@ -355,21 +355,22 @@ namespace ts {
|
||||||
return { program, exitStatus };
|
return { program, exitStatus };
|
||||||
|
|
||||||
function compileProgram(): ExitStatus {
|
function compileProgram(): ExitStatus {
|
||||||
// First get any syntactic errors.
|
let diagnostics: Diagnostic[];
|
||||||
let diagnostics = program.getSyntacticDiagnostics();
|
|
||||||
reportDiagnostics(diagnostics);
|
// First get and report any syntactic errors.
|
||||||
|
diagnostics = program.getSyntacticDiagnostics();
|
||||||
|
|
||||||
// If we didn't have any syntactic errors, then also try getting the global and
|
// If we didn't have any syntactic errors, then also try getting the global and
|
||||||
// semantic errors.
|
// semantic errors.
|
||||||
if (diagnostics.length === 0) {
|
if (diagnostics.length === 0) {
|
||||||
let diagnostics = program.getGlobalDiagnostics();
|
diagnostics = program.getGlobalDiagnostics();
|
||||||
reportDiagnostics(diagnostics);
|
|
||||||
|
|
||||||
if (diagnostics.length === 0) {
|
if (diagnostics.length === 0) {
|
||||||
let diagnostics = program.getSemanticDiagnostics();
|
diagnostics = program.getSemanticDiagnostics();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reportDiagnostics(diagnostics);
|
reportDiagnostics(diagnostics);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the user doesn't want us to emit, then we're done at this point.
|
// If the user doesn't want us to emit, then we're done at this point.
|
||||||
if (compilerOptions.noEmit) {
|
if (compilerOptions.noEmit) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
// token > SyntaxKind.Identifer => token is a keyword
|
// token > SyntaxKind.Identifer => token is a keyword
|
||||||
|
// Also, If you add a new SyntaxKind be sure to keep the `Markers` section at the bottom in sync
|
||||||
export const enum SyntaxKind {
|
export const enum SyntaxKind {
|
||||||
Unknown,
|
Unknown,
|
||||||
EndOfFileToken,
|
EndOfFileToken,
|
||||||
|
@ -24,6 +25,8 @@ namespace ts {
|
||||||
MultiLineCommentTrivia,
|
MultiLineCommentTrivia,
|
||||||
NewLineTrivia,
|
NewLineTrivia,
|
||||||
WhitespaceTrivia,
|
WhitespaceTrivia,
|
||||||
|
// We detect and preserve #! on the first line
|
||||||
|
ShebangTrivia,
|
||||||
// We detect and provide better error recovery when we encounter a git merge marker. This
|
// We detect and provide better error recovery when we encounter a git merge marker. This
|
||||||
// allows us to edit files with git-conflict markers in them in a much more pleasant manner.
|
// allows us to edit files with git-conflict markers in them in a much more pleasant manner.
|
||||||
ConflictMarkerTrivia,
|
ConflictMarkerTrivia,
|
||||||
|
|
|
@ -75,28 +75,28 @@ function delint(sourceFile) {
|
||||||
delintNode(sourceFile);
|
delintNode(sourceFile);
|
||||||
function delintNode(node) {
|
function delintNode(node) {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case 196 /* ForStatement */:
|
case 197 /* ForStatement */:
|
||||||
case 197 /* ForInStatement */:
|
case 198 /* ForInStatement */:
|
||||||
case 195 /* WhileStatement */:
|
case 196 /* WhileStatement */:
|
||||||
case 194 /* DoStatement */:
|
case 195 /* DoStatement */:
|
||||||
if (node.statement.kind !== 189 /* Block */) {
|
if (node.statement.kind !== 190 /* Block */) {
|
||||||
report(node, "A looping statement's contents should be wrapped in a block body.");
|
report(node, "A looping statement's contents should be wrapped in a block body.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 193 /* IfStatement */:
|
case 194 /* IfStatement */:
|
||||||
var ifStatement = node;
|
var ifStatement = node;
|
||||||
if (ifStatement.thenStatement.kind !== 189 /* Block */) {
|
if (ifStatement.thenStatement.kind !== 190 /* Block */) {
|
||||||
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
|
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
|
||||||
}
|
}
|
||||||
if (ifStatement.elseStatement &&
|
if (ifStatement.elseStatement &&
|
||||||
ifStatement.elseStatement.kind !== 189 /* Block */ &&
|
ifStatement.elseStatement.kind !== 190 /* Block */ &&
|
||||||
ifStatement.elseStatement.kind !== 193 /* IfStatement */) {
|
ifStatement.elseStatement.kind !== 194 /* IfStatement */) {
|
||||||
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
|
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 178 /* BinaryExpression */:
|
case 179 /* BinaryExpression */:
|
||||||
var op = node.operatorToken.kind;
|
var op = node.operatorToken.kind;
|
||||||
if (op === 29 /* EqualsEqualsToken */ || op == 30 /* ExclamationEqualsToken */) {
|
if (op === 30 /* EqualsEqualsToken */ || op == 31 /* ExclamationEqualsToken */) {
|
||||||
report(node, "Use '===' and '!=='.");
|
report(node, "Use '===' and '!=='.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -139,14 +139,14 @@ var __extends = (this && this.__extends) || function (d, b) {
|
||||||
//super property access in instance member accessor(get and set) of class with no base type
|
//super property access in instance member accessor(get and set) of class with no base type
|
||||||
var NoBase = (function () {
|
var NoBase = (function () {
|
||||||
function NoBase() {
|
function NoBase() {
|
||||||
this.m = _super.prototype;
|
this.m = _super.prototype.prototype;
|
||||||
this.n = _super.hasOwnProperty.call(this, '');
|
this.n = _super.prototype.hasOwnProperty.call(this, '');
|
||||||
var a = _super.prototype;
|
var a = _super.prototype.prototype;
|
||||||
var b = _super.hasOwnProperty.call(this, '');
|
var b = _super.prototype.hasOwnProperty.call(this, '');
|
||||||
}
|
}
|
||||||
NoBase.prototype.fn = function () {
|
NoBase.prototype.fn = function () {
|
||||||
var a = _super.prototype;
|
var a = _super.prototype.prototype;
|
||||||
var b = _super.hasOwnProperty.call(this, '');
|
var b = _super.prototype.hasOwnProperty.call(this, '');
|
||||||
};
|
};
|
||||||
//super static property access in static member function of class with no base type
|
//super static property access in static member function of class with no base type
|
||||||
//super static property access in static member accessor(get and set) of class with no base type
|
//super static property access in static member accessor(get and set) of class with no base type
|
||||||
|
|
|
@ -18,7 +18,7 @@ var C = (function () {
|
||||||
function C() {
|
function C() {
|
||||||
}
|
}
|
||||||
C.prototype.foo = function () {
|
C.prototype.foo = function () {
|
||||||
_super.foo.call(this);
|
_super.prototype.foo.call(this);
|
||||||
};
|
};
|
||||||
return C;
|
return C;
|
||||||
})();
|
})();
|
||||||
|
@ -30,7 +30,7 @@ var M1;
|
||||||
function C() {
|
function C() {
|
||||||
}
|
}
|
||||||
C.prototype.foo = function () {
|
C.prototype.foo = function () {
|
||||||
_super.foo.call(this);
|
_super.prototype.foo.call(this);
|
||||||
};
|
};
|
||||||
return C;
|
return C;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -10,7 +10,7 @@ var C = (function () {
|
||||||
function C() {
|
function C() {
|
||||||
}
|
}
|
||||||
C.prototype.M = function () {
|
C.prototype.M = function () {
|
||||||
_super..call(this, 0);
|
_super.prototype..call(this, 0);
|
||||||
};
|
};
|
||||||
return C;
|
return C;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -18,7 +18,7 @@ var C = (function () {
|
||||||
function C() {
|
function C() {
|
||||||
}
|
}
|
||||||
C.prototype.foo = function () {
|
C.prototype.foo = function () {
|
||||||
_super.foo = 1;
|
_super.prototype.foo = 1;
|
||||||
};
|
};
|
||||||
return C;
|
return C;
|
||||||
})();
|
})();
|
||||||
|
@ -30,7 +30,7 @@ var M1;
|
||||||
function C() {
|
function C() {
|
||||||
}
|
}
|
||||||
C.prototype.foo = function () {
|
C.prototype.foo = function () {
|
||||||
_super.foo = 1;
|
_super.prototype.foo = 1;
|
||||||
};
|
};
|
||||||
return C;
|
return C;
|
||||||
})();
|
})();
|
||||||
|
|
8
tests/baselines/reference/shebang.js
Normal file
8
tests/baselines/reference/shebang.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//// [shebang.ts]
|
||||||
|
#!/usr/bin/env node
|
||||||
|
var foo = 'I wish the generated JS to be executed in node';
|
||||||
|
|
||||||
|
|
||||||
|
//// [shebang.js]
|
||||||
|
#!/usr/bin/env node
|
||||||
|
var foo = 'I wish the generated JS to be executed in node';
|
5
tests/baselines/reference/shebang.symbols
Normal file
5
tests/baselines/reference/shebang.symbols
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
=== tests/cases/compiler/shebang.ts ===
|
||||||
|
#!/usr/bin/env node
|
||||||
|
var foo = 'I wish the generated JS to be executed in node';
|
||||||
|
>foo : Symbol(foo, Decl(shebang.ts, 1, 3))
|
||||||
|
|
6
tests/baselines/reference/shebang.types
Normal file
6
tests/baselines/reference/shebang.types
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
=== tests/cases/compiler/shebang.ts ===
|
||||||
|
#!/usr/bin/env node
|
||||||
|
var foo = 'I wish the generated JS to be executed in node';
|
||||||
|
>foo : string
|
||||||
|
>'I wish the generated JS to be executed in node' : string
|
||||||
|
|
20
tests/baselines/reference/shebangError.errors.txt
Normal file
20
tests/baselines/reference/shebangError.errors.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
tests/cases/compiler/shebangError.ts(2,1): error TS1127: Invalid character.
|
||||||
|
tests/cases/compiler/shebangError.ts(2,2): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||||
|
tests/cases/compiler/shebangError.ts(2,12): error TS2304: Cannot find name 'env'.
|
||||||
|
tests/cases/compiler/shebangError.ts(2,16): error TS1005: ';' expected.
|
||||||
|
tests/cases/compiler/shebangError.ts(2,16): error TS2304: Cannot find name 'node'.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/shebangError.ts (5 errors) ====
|
||||||
|
var foo = 'Shebang is only allowed on the first line';
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
!!! error TS1127: Invalid character.
|
||||||
|
~~~~~~~~~
|
||||||
|
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||||
|
~~~
|
||||||
|
!!! error TS2304: Cannot find name 'env'.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS2304: Cannot find name 'node'.
|
8
tests/baselines/reference/shebangError.js
Normal file
8
tests/baselines/reference/shebangError.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//// [shebangError.ts]
|
||||||
|
var foo = 'Shebang is only allowed on the first line';
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
//// [shebangError.js]
|
||||||
|
var foo = 'Shebang is only allowed on the first line';
|
||||||
|
!/usr/bin / env;
|
||||||
|
node;
|
|
@ -79,7 +79,7 @@ var Base2 = (function () {
|
||||||
function Base2() {
|
function Base2() {
|
||||||
}
|
}
|
||||||
Base2.prototype.foo = function () {
|
Base2.prototype.foo = function () {
|
||||||
_super.foo.call(this);
|
_super.prototype.foo.call(this);
|
||||||
};
|
};
|
||||||
return Base2;
|
return Base2;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -165,7 +165,7 @@ var Base4;
|
||||||
function Sub4E() {
|
function Sub4E() {
|
||||||
}
|
}
|
||||||
Sub4E.prototype.x = function () {
|
Sub4E.prototype.x = function () {
|
||||||
return _super.x.call(this);
|
return _super.prototype.x.call(this);
|
||||||
};
|
};
|
||||||
return Sub4E;
|
return Sub4E;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
tests/cases/compiler/superCallWithMissingBaseClass.ts(1,19): error TS2304: Cannot find name 'Bar'.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/superCallWithMissingBaseClass.ts (1 errors) ====
|
||||||
|
class Foo extends Bar {
|
||||||
|
~~~
|
||||||
|
!!! error TS2304: Cannot find name 'Bar'.
|
||||||
|
m1() {
|
||||||
|
return super.m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
static m2() {
|
||||||
|
return super.m2();
|
||||||
|
}
|
||||||
|
}
|
30
tests/baselines/reference/superCallWithMissingBaseClass.js
Normal file
30
tests/baselines/reference/superCallWithMissingBaseClass.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
//// [superCallWithMissingBaseClass.ts]
|
||||||
|
class Foo extends Bar {
|
||||||
|
m1() {
|
||||||
|
return super.m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
static m2() {
|
||||||
|
return super.m2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [superCallWithMissingBaseClass.js]
|
||||||
|
var __extends = (this && this.__extends) || function (d, b) {
|
||||||
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
var Foo = (function (_super) {
|
||||||
|
__extends(Foo, _super);
|
||||||
|
function Foo() {
|
||||||
|
_super.apply(this, arguments);
|
||||||
|
}
|
||||||
|
Foo.prototype.m1 = function () {
|
||||||
|
return _super.prototype.m1.call(this);
|
||||||
|
};
|
||||||
|
Foo.m2 = function () {
|
||||||
|
return _super.m2.call(this);
|
||||||
|
};
|
||||||
|
return Foo;
|
||||||
|
})(Bar);
|
55
tests/baselines/reference/systemModuleWithSuperClass.js
Normal file
55
tests/baselines/reference/systemModuleWithSuperClass.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
//// [tests/cases/compiler/systemModuleWithSuperClass.ts] ////
|
||||||
|
|
||||||
|
//// [foo.ts]
|
||||||
|
|
||||||
|
export class Foo {
|
||||||
|
a: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [bar.ts]
|
||||||
|
import {Foo} from './foo';
|
||||||
|
export class Bar extends Foo {
|
||||||
|
b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
//// [foo.js]
|
||||||
|
System.register([], function(exports_1) {
|
||||||
|
var Foo;
|
||||||
|
return {
|
||||||
|
setters:[],
|
||||||
|
execute: function() {
|
||||||
|
Foo = (function () {
|
||||||
|
function Foo() {
|
||||||
|
}
|
||||||
|
return Foo;
|
||||||
|
})();
|
||||||
|
exports_1("Foo", Foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//// [bar.js]
|
||||||
|
System.register(['./foo'], function(exports_1) {
|
||||||
|
var __extends = (this && this.__extends) || function (d, b) {
|
||||||
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
var foo_1;
|
||||||
|
var Bar;
|
||||||
|
return {
|
||||||
|
setters:[
|
||||||
|
function (_foo_1) {
|
||||||
|
foo_1 = _foo_1;
|
||||||
|
}],
|
||||||
|
execute: function() {
|
||||||
|
Bar = (function (_super) {
|
||||||
|
__extends(Bar, _super);
|
||||||
|
function Bar() {
|
||||||
|
_super.apply(this, arguments);
|
||||||
|
}
|
||||||
|
return Bar;
|
||||||
|
})(foo_1.Foo);
|
||||||
|
exports_1("Bar", Bar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
20
tests/baselines/reference/systemModuleWithSuperClass.symbols
Normal file
20
tests/baselines/reference/systemModuleWithSuperClass.symbols
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
=== tests/cases/compiler/foo.ts ===
|
||||||
|
|
||||||
|
export class Foo {
|
||||||
|
>Foo : Symbol(Foo, Decl(foo.ts, 0, 0))
|
||||||
|
|
||||||
|
a: string;
|
||||||
|
>a : Symbol(a, Decl(foo.ts, 1, 18))
|
||||||
|
}
|
||||||
|
|
||||||
|
=== tests/cases/compiler/bar.ts ===
|
||||||
|
import {Foo} from './foo';
|
||||||
|
>Foo : Symbol(Foo, Decl(bar.ts, 0, 8))
|
||||||
|
|
||||||
|
export class Bar extends Foo {
|
||||||
|
>Bar : Symbol(Bar, Decl(bar.ts, 0, 26))
|
||||||
|
>Foo : Symbol(Foo, Decl(bar.ts, 0, 8))
|
||||||
|
|
||||||
|
b: string;
|
||||||
|
>b : Symbol(b, Decl(bar.ts, 1, 30))
|
||||||
|
}
|
20
tests/baselines/reference/systemModuleWithSuperClass.types
Normal file
20
tests/baselines/reference/systemModuleWithSuperClass.types
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
=== tests/cases/compiler/foo.ts ===
|
||||||
|
|
||||||
|
export class Foo {
|
||||||
|
>Foo : Foo
|
||||||
|
|
||||||
|
a: string;
|
||||||
|
>a : string
|
||||||
|
}
|
||||||
|
|
||||||
|
=== tests/cases/compiler/bar.ts ===
|
||||||
|
import {Foo} from './foo';
|
||||||
|
>Foo : typeof Foo
|
||||||
|
|
||||||
|
export class Bar extends Foo {
|
||||||
|
>Bar : Bar
|
||||||
|
>Foo : Foo
|
||||||
|
|
||||||
|
b: string;
|
||||||
|
>b : string
|
||||||
|
}
|
2
tests/cases/compiler/shebang.ts
Normal file
2
tests/cases/compiler/shebang.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
var foo = 'I wish the generated JS to be executed in node';
|
2
tests/cases/compiler/shebangError.ts
Normal file
2
tests/cases/compiler/shebangError.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
var foo = 'Shebang is only allowed on the first line';
|
||||||
|
#!/usr/bin/env node
|
9
tests/cases/compiler/superCallWithMissingBaseClass.ts
Normal file
9
tests/cases/compiler/superCallWithMissingBaseClass.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
class Foo extends Bar {
|
||||||
|
m1() {
|
||||||
|
return super.m1();
|
||||||
|
}
|
||||||
|
|
||||||
|
static m2() {
|
||||||
|
return super.m2();
|
||||||
|
}
|
||||||
|
}
|
12
tests/cases/compiler/systemModuleWithSuperClass.ts
Normal file
12
tests/cases/compiler/systemModuleWithSuperClass.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// @module: system
|
||||||
|
|
||||||
|
// @Filename: foo.ts
|
||||||
|
export class Foo {
|
||||||
|
a: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Filename: bar.ts
|
||||||
|
import {Foo} from './foo';
|
||||||
|
export class Bar extends Foo {
|
||||||
|
b: string;
|
||||||
|
}
|
17
tslint.json
17
tslint.json
|
@ -4,20 +4,31 @@
|
||||||
"comment-format": [true,
|
"comment-format": [true,
|
||||||
"check-space"
|
"check-space"
|
||||||
],
|
],
|
||||||
"indent": true,
|
"indent": [true,
|
||||||
|
"spaces"
|
||||||
|
],
|
||||||
"one-line": [true,
|
"one-line": [true,
|
||||||
"check-open-brace"
|
"check-open-brace"
|
||||||
],
|
],
|
||||||
"no-unreachable": true,
|
"no-unreachable": true,
|
||||||
"no-use-before-declare": true,
|
"no-use-before-declare": true,
|
||||||
"no-var-keyword": true,
|
"no-var-keyword": true,
|
||||||
"quotemark": true,
|
"quotemark": [true,
|
||||||
|
"double"
|
||||||
|
],
|
||||||
"semicolon": true,
|
"semicolon": true,
|
||||||
"whitespace": [true,
|
"whitespace": [true,
|
||||||
"check-branch",
|
"check-branch",
|
||||||
"check-operator",
|
"check-operator",
|
||||||
"check-separator",
|
"check-separator",
|
||||||
"check-type"
|
"check-type"
|
||||||
]
|
],
|
||||||
|
"typedef-whitespace": [true, {
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue