Skip to content

Commit d1c467f

Browse files
committed
Merge branch 'master' into use-common-directory-for-out
2 parents 02a9b11 + b5c64ad commit d1c467f

1,508 files changed

Lines changed: 20204 additions & 16060 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/checker.ts

Lines changed: 92 additions & 49 deletions
Large diffs are not rendered by default.

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ namespace ts {
357357
case SyntaxKind.SymbolKeyword:
358358
case SyntaxKind.VoidKeyword:
359359
case SyntaxKind.ThisType:
360-
case SyntaxKind.StringLiteral:
360+
case SyntaxKind.StringLiteralType:
361361
return writeTextOfNode(currentText, type);
362362
case SyntaxKind.ExpressionWithTypeArguments:
363363
return emitExpressionWithTypeArguments(<ExpressionWithTypeArguments>type);

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@
16221622
},
16231623
"Cannot assign an abstract constructor type to a non-abstract constructor type.": {
16241624
"category": "Error",
1625-
"code":2517
1625+
"code": 2517
16261626
},
16271627
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
16281628
"category": "Error",
@@ -2068,6 +2068,14 @@
20682068
"category": "Error",
20692069
"code": 5056
20702070
},
2071+
"Cannot find a tsconfig.json file at the specified directory: '{0}'": {
2072+
"category": "Error",
2073+
"code": 5057
2074+
},
2075+
"The specified path does not exist: '{0}'": {
2076+
"category": "Error",
2077+
"code": 5058
2078+
},
20712079

20722080
"Concatenate and emit output to single file.": {
20732081
"category": "Message",

src/compiler/emitter.ts

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
402402
*/
403403
argumentsName?: string;
404404

405+
/*
406+
* alias for 'this' from the calling code stack frame in case if this was used inside the converted loop
407+
*/
408+
thisName?: string;
409+
405410
/*
406411
* list of non-block scoped variable declarations that appear inside converted loop
407412
* such variable declarations should be moved outside the loop body
@@ -1271,7 +1276,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
12711276
}
12721277
}
12731278

1274-
function isBinaryOrOctalIntegerLiteral(node: LiteralExpression, text: string): boolean {
1279+
function isBinaryOrOctalIntegerLiteral(node: LiteralLikeNode, text: string): boolean {
12751280
if (node.kind === SyntaxKind.NumericLiteral && text.length > 1) {
12761281
switch (text.charCodeAt(1)) {
12771282
case CharacterCodes.b:
@@ -1285,7 +1290,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
12851290
return false;
12861291
}
12871292

1288-
function emitLiteral(node: LiteralExpression) {
1293+
function emitLiteral(node: LiteralExpression | TemplateLiteralFragment) {
12891294
const text = getLiteralText(node);
12901295

12911296
if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) {
@@ -1300,7 +1305,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
13001305
}
13011306
}
13021307

1303-
function getLiteralText(node: LiteralExpression) {
1308+
function getLiteralText(node: LiteralExpression | TemplateLiteralFragment) {
13041309
// Any template literal or string literal with an extended escape
13051310
// (e.g. "\u{0067}") will need to be downleveled as a escaped string literal.
13061311
if (languageVersion < ScriptTarget.ES6 && (isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) {
@@ -1359,7 +1364,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
13591364
write(`"${text}"`);
13601365
}
13611366

1362-
function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, literalEmitter: (literal: LiteralExpression) => void) {
1367+
function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, literalEmitter: (literal: LiteralExpression | TemplateLiteralFragment) => void) {
13631368
write("[");
13641369
if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) {
13651370
literalEmitter(<LiteralExpression>node.template);
@@ -1992,6 +1997,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
19921997
if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LexicalThis) {
19931998
write("_this");
19941999
}
2000+
else if (convertedLoopState) {
2001+
write(convertedLoopState.thisName || (convertedLoopState.thisName = makeUniqueName("this")));
2002+
}
19952003
else {
19962004
write("this");
19972005
}
@@ -3322,6 +3330,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
33223330
convertedLoopState.argumentsName = convertedOuterLoopState.argumentsName;
33233331
}
33243332

3333+
if (convertedOuterLoopState.thisName) {
3334+
// outer loop has already used 'this' so we've already have some name to alias it
3335+
// use the same name in all nested loops
3336+
convertedLoopState.thisName = convertedOuterLoopState.thisName;
3337+
}
3338+
33253339
if (convertedOuterLoopState.hoistedLocalVariables) {
33263340
// we've already collected some non-block scoped variable declarations in enclosing loop
33273341
// use the same storage in nested loop
@@ -3351,6 +3365,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
33513365
writeLine();
33523366
}
33533367
}
3368+
if (convertedLoopState.thisName) {
3369+
// if alias for this is set
3370+
if (convertedOuterLoopState) {
3371+
// pass it to outer converted loop
3372+
convertedOuterLoopState.thisName = convertedLoopState.thisName;
3373+
}
3374+
else {
3375+
// this is top level converted loop so we need to create an alias for 'this' here
3376+
// NOTE:
3377+
// if converted loops were all nested in arrow function then we'll always emit '_this' so convertedLoopState.thisName will not be set.
3378+
// If it is set this means that all nested loops are not nested in arrow function and it is safe to capture 'this'.
3379+
write(`var ${convertedLoopState.thisName} = this;`);
3380+
writeLine();
3381+
}
3382+
}
33543383

33553384
if (convertedLoopState.hoistedLocalVariables) {
33563385
// if hoistedLocalVariables !== undefined this means that we've possibly collected some variable declarations to be hoisted later
@@ -5925,7 +5954,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
59255954

59265955
function emitSerializedTypeNode(node: TypeNode) {
59275956
if (node) {
5928-
59295957
switch (node.kind) {
59305958
case SyntaxKind.VoidKeyword:
59315959
write("void 0");
@@ -5951,7 +5979,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
59515979
return;
59525980

59535981
case SyntaxKind.StringKeyword:
5954-
case SyntaxKind.StringLiteral:
5982+
case SyntaxKind.StringLiteralType:
59555983
write("String");
59565984
return;
59575985

@@ -7354,7 +7382,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
73547382
write(`], function(${exportFunctionForFile}) {`);
73557383
writeLine();
73567384
increaseIndent();
7357-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
7385+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
73587386
emitEmitHelpers(node);
73597387
emitCaptureThisForNodeIfNecessary(node);
73607388
emitSystemModuleBody(node, dependencyGroups, startIndex);
@@ -7457,7 +7485,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
74577485
writeModuleName(node, emitRelativePathAsModuleName);
74587486
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName);
74597487
increaseIndent();
7460-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
7488+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
74617489
emitExportStarHelper();
74627490
emitCaptureThisForNodeIfNecessary(node);
74637491
emitLinesStartingAt(node.statements, startIndex);
@@ -7469,7 +7497,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
74697497
}
74707498

74717499
function emitCommonJSModule(node: SourceFile) {
7472-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
7500+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ true);
74737501
emitEmitHelpers(node);
74747502
collectExternalModuleInfo(node);
74757503
emitExportStarHelper();
@@ -7498,7 +7526,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
74987526
})(`);
74997527
emitAMDFactoryHeader(dependencyNames);
75007528
increaseIndent();
7501-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
7529+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
75027530
emitExportStarHelper();
75037531
emitCaptureThisForNodeIfNecessary(node);
75047532
emitLinesStartingAt(node.statements, startIndex);
@@ -7640,19 +7668,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
76407668
}
76417669
}
76427670

7643-
function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean): number {
7671+
function isUseStrictPrologue(node: ExpressionStatement): boolean {
7672+
return !!(node.expression as StringLiteral).text.match(/use strict/);
7673+
}
7674+
7675+
function ensureUseStrictPrologue(startWithNewLine: boolean, writeUseStrict: boolean) {
7676+
if (writeUseStrict) {
7677+
if (startWithNewLine) {
7678+
writeLine();
7679+
}
7680+
write("\"use strict\";");
7681+
}
7682+
}
7683+
7684+
function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean, ensureUseStrict?: boolean): number {
7685+
let foundUseStrict = false;
76447686
for (let i = 0; i < statements.length; ++i) {
76457687
if (isPrologueDirective(statements[i])) {
7688+
if (isUseStrictPrologue(statements[i] as ExpressionStatement)) {
7689+
foundUseStrict = true;
7690+
}
76467691
if (startWithNewLine || i > 0) {
76477692
writeLine();
76487693
}
76497694
emit(statements[i]);
76507695
}
76517696
else {
7697+
ensureUseStrictPrologue(startWithNewLine || i > 0, !foundUseStrict && ensureUseStrict);
76527698
// return index of the first non prologue directive
76537699
return i;
76547700
}
76557701
}
7702+
ensureUseStrictPrologue(startWithNewLine, !foundUseStrict && ensureUseStrict);
76567703
return statements.length;
76577704
}
76587705

src/compiler/parser.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ namespace ts {
18741874
function parseTemplateExpression(): TemplateExpression {
18751875
const template = <TemplateExpression>createNode(SyntaxKind.TemplateExpression);
18761876

1877-
template.head = parseLiteralNode();
1877+
template.head = parseTemplateLiteralFragment();
18781878
Debug.assert(template.head.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind");
18791879

18801880
const templateSpans = <NodeArray<TemplateSpan>>[];
@@ -1895,22 +1895,34 @@ namespace ts {
18951895
const span = <TemplateSpan>createNode(SyntaxKind.TemplateSpan);
18961896
span.expression = allowInAnd(parseExpression);
18971897

1898-
let literal: LiteralExpression;
1898+
let literal: TemplateLiteralFragment;
18991899

19001900
if (token === SyntaxKind.CloseBraceToken) {
19011901
reScanTemplateToken();
1902-
literal = parseLiteralNode();
1902+
literal = parseTemplateLiteralFragment();
19031903
}
19041904
else {
1905-
literal = <LiteralExpression>parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken));
1905+
literal = <TemplateLiteralFragment>parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken));
19061906
}
19071907

19081908
span.literal = literal;
19091909
return finishNode(span);
19101910
}
19111911

1912+
function parseStringLiteralTypeNode(): StringLiteralTypeNode {
1913+
return <StringLiteralTypeNode>parseLiteralLikeNode(SyntaxKind.StringLiteralType, /*internName*/ true);
1914+
}
1915+
19121916
function parseLiteralNode(internName?: boolean): LiteralExpression {
1913-
const node = <LiteralExpression>createNode(token);
1917+
return <LiteralExpression>parseLiteralLikeNode(token, internName);
1918+
}
1919+
1920+
function parseTemplateLiteralFragment(): TemplateLiteralFragment {
1921+
return <TemplateLiteralFragment>parseLiteralLikeNode(token, /*internName*/ false);
1922+
}
1923+
1924+
function parseLiteralLikeNode(kind: SyntaxKind, internName: boolean): LiteralLikeNode {
1925+
const node = <LiteralExpression>createNode(kind);
19141926
const text = scanner.getTokenValue();
19151927
node.text = internName ? internIdentifier(text) : text;
19161928

@@ -2397,7 +2409,7 @@ namespace ts {
23972409
const node = tryParse(parseKeywordAndNoDot);
23982410
return node || parseTypeReferenceOrTypePredicate();
23992411
case SyntaxKind.StringLiteral:
2400-
return <StringLiteral>parseLiteralNode(/*internName*/ true);
2412+
return parseStringLiteralTypeNode();
24012413
case SyntaxKind.VoidKeyword:
24022414
return parseTokenNode<TypeNode>();
24032415
case SyntaxKind.ThisKeyword:

src/compiler/tsc.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,26 @@ namespace ts {
295295
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"), /* compilerHost */ undefined);
296296
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
297297
}
298-
configFileName = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json"));
299298
if (commandLine.fileNames.length !== 0) {
300299
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line), /* compilerHost */ undefined);
301300
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
302301
}
302+
303+
const fileOrDirectory = normalizePath(commandLine.options.project);
304+
if (!fileOrDirectory /* current directory "." */ || sys.directoryExists(fileOrDirectory)) {
305+
configFileName = combinePaths(fileOrDirectory, "tsconfig.json");
306+
if (!sys.fileExists(configFileName)) {
307+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0, commandLine.options.project), /* compilerHost */ undefined);
308+
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
309+
}
310+
}
311+
else {
312+
configFileName = fileOrDirectory;
313+
if (!sys.fileExists(configFileName)) {
314+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, commandLine.options.project), /* compilerHost */ undefined);
315+
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
316+
}
317+
}
303318
}
304319
else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
305320
const searchPath = normalizePath(sys.getCurrentDirectory());

src/compiler/types.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ namespace ts {
205205
IntersectionType,
206206
ParenthesizedType,
207207
ThisType,
208+
StringLiteralType,
208209
// Binding patterns
209210
ObjectBindingPattern,
210211
ArrayBindingPattern,
@@ -350,7 +351,7 @@ namespace ts {
350351
FirstFutureReservedWord = ImplementsKeyword,
351352
LastFutureReservedWord = YieldKeyword,
352353
FirstTypeNode = TypePredicate,
353-
LastTypeNode = ThisType,
354+
LastTypeNode = StringLiteralType,
354355
FirstPunctuation = OpenBraceToken,
355356
LastPunctuation = CaretEqualsToken,
356357
FirstToken = Unknown,
@@ -790,10 +791,13 @@ namespace ts {
790791
type: TypeNode;
791792
}
792793

793-
// Note that a StringLiteral AST node is both an Expression and a TypeNode. The latter is
794-
// because string literals can appear in type annotations as well.
794+
// @kind(SyntaxKind.StringLiteralType)
795+
export interface StringLiteralTypeNode extends LiteralLikeNode, TypeNode {
796+
_stringLiteralTypeBrand: any;
797+
}
798+
795799
// @kind(SyntaxKind.StringLiteral)
796-
export interface StringLiteral extends LiteralExpression, TypeNode {
800+
export interface StringLiteral extends LiteralExpression {
797801
_stringLiteralBrand: any;
798802
}
799803

@@ -911,24 +915,32 @@ namespace ts {
911915
body: ConciseBody;
912916
}
913917

918+
export interface LiteralLikeNode extends Node {
919+
text: string;
920+
isUnterminated?: boolean;
921+
hasExtendedUnicodeEscape?: boolean;
922+
}
923+
914924
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
915925
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters.
916926
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
917927
// @kind(SyntaxKind.NumericLiteral)
918928
// @kind(SyntaxKind.RegularExpressionLiteral)
919929
// @kind(SyntaxKind.NoSubstitutionTemplateLiteral)
930+
export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression {
931+
_literalExpressionBrand: any;
932+
}
933+
920934
// @kind(SyntaxKind.TemplateHead)
921935
// @kind(SyntaxKind.TemplateMiddle)
922936
// @kind(SyntaxKind.TemplateTail)
923-
export interface LiteralExpression extends PrimaryExpression {
924-
text: string;
925-
isUnterminated?: boolean;
926-
hasExtendedUnicodeEscape?: boolean;
937+
export interface TemplateLiteralFragment extends LiteralLikeNode {
938+
_templateLiteralFragmentBrand: any;
927939
}
928940

929941
// @kind(SyntaxKind.TemplateExpression)
930942
export interface TemplateExpression extends PrimaryExpression {
931-
head: LiteralExpression;
943+
head: TemplateLiteralFragment;
932944
templateSpans: NodeArray<TemplateSpan>;
933945
}
934946

@@ -937,7 +949,7 @@ namespace ts {
937949
// @kind(SyntaxKind.TemplateSpan)
938950
export interface TemplateSpan extends Node {
939951
expression: Expression;
940-
literal: LiteralExpression;
952+
literal: TemplateLiteralFragment;
941953
}
942954

943955
// @kind(SyntaxKind.ParenthesizedExpression)

0 commit comments

Comments
 (0)