Skip to content

Commit 27deb31

Browse files
committed
Merge remote-tracking branch 'origin/master' into tsserver-typings
2 parents edfd104 + b8963ba commit 27deb31

32 files changed

Lines changed: 571 additions & 73 deletions

File tree

Jakefile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ var harnessSources = harnessCoreSources.concat([
209209
"convertCompilerOptionsFromJson.ts",
210210
"convertTypingOptionsFromJson.ts",
211211
"tsserverProjectSystem.ts",
212-
"matchFiles.ts"
212+
"matchFiles.ts",
213+
"initializeTSConfig.ts",
213214
].map(function (f) {
214215
return path.join(unittestsDirectory, f);
215216
})).concat([

scripts/ior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../src/harness/external/node.d.ts" />
1+
/// <reference types="node"/>
22

33
import fs = require('fs');
44
import path = require('path');

src/compiler/commandLineParser.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ namespace ts {
126126
type: "boolean",
127127
description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported,
128128
},
129+
{
130+
name: "noErrorTruncation",
131+
type: "boolean"
132+
},
129133
{
130134
name: "noImplicitAny",
131135
type: "boolean",
@@ -462,6 +466,14 @@ namespace ts {
462466
shortOptionNames: Map<string>;
463467
}
464468

469+
/* @internal */
470+
export const defaultInitCompilerOptions: CompilerOptions = {
471+
module: ModuleKind.CommonJS,
472+
target: ScriptTarget.ES5,
473+
noImplicitAny: false,
474+
sourceMap: false,
475+
};
476+
465477
let optionNameMapCache: OptionNameMap;
466478

467479
/* @internal */
@@ -667,6 +679,94 @@ namespace ts {
667679
}
668680
}
669681

682+
/**
683+
* Generate tsconfig configuration when running command line "--init"
684+
* @param options commandlineOptions to be generated into tsconfig.json
685+
* @param fileNames array of filenames to be generated into tsconfig.json
686+
*/
687+
/* @internal */
688+
export function generateTSConfig(options: CompilerOptions, fileNames: string[]): { compilerOptions: Map<CompilerOptionsValue> } {
689+
const compilerOptions = extend(options, defaultInitCompilerOptions);
690+
const configurations: any = {
691+
compilerOptions: serializeCompilerOptions(compilerOptions)
692+
};
693+
if (fileNames && fileNames.length) {
694+
// only set the files property if we have at least one file
695+
configurations.files = fileNames;
696+
}
697+
698+
return configurations;
699+
700+
function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map<string | number> | undefined {
701+
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean") {
702+
// this is of a type CommandLineOptionOfPrimitiveType
703+
return undefined;
704+
}
705+
else if (optionDefinition.type === "list") {
706+
return getCustomTypeMapOfCommandLineOption((<CommandLineOptionOfListType>optionDefinition).element);
707+
}
708+
else {
709+
return (<CommandLineOptionOfCustomType>optionDefinition).type;
710+
}
711+
}
712+
713+
function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: MapLike<string | number>): string | undefined {
714+
// There is a typeMap associated with this command-line option so use it to map value back to its name
715+
for (const key in customTypeMap) {
716+
if (customTypeMap[key] === value) {
717+
return key;
718+
}
719+
}
720+
return undefined;
721+
}
722+
723+
function serializeCompilerOptions(options: CompilerOptions): Map<CompilerOptionsValue> {
724+
const result = createMap<CompilerOptionsValue>();
725+
const optionsNameMap = getOptionNameMap().optionNameMap;
726+
727+
for (const name in options) {
728+
if (hasProperty(options, name)) {
729+
// tsconfig only options cannot be specified via command line,
730+
// so we can assume that only types that can appear here string | number | boolean
731+
switch (name) {
732+
case "init":
733+
case "watch":
734+
case "version":
735+
case "help":
736+
case "project":
737+
break;
738+
default:
739+
const value = options[name];
740+
let optionDefinition = optionsNameMap[name.toLowerCase()];
741+
if (optionDefinition) {
742+
const customTypeMap = getCustomTypeMapOfCommandLineOption(optionDefinition);
743+
if (!customTypeMap) {
744+
// There is no map associated with this compiler option then use the value as-is
745+
// This is the case if the value is expect to be string, number, boolean or list of string
746+
result[name] = value;
747+
}
748+
else {
749+
if (optionDefinition.type === "list") {
750+
const convertedValue: string[] = [];
751+
for (const element of value as (string | number)[]) {
752+
convertedValue.push(getNameOfCompilerOptionValue(element, customTypeMap));
753+
}
754+
result[name] = convertedValue;
755+
}
756+
else {
757+
// There is a typeMap associated with this command-line option so use it to map value back to its name
758+
result[name] = getNameOfCompilerOptionValue(value, customTypeMap);
759+
}
760+
}
761+
}
762+
break;
763+
}
764+
}
765+
}
766+
return result;
767+
}
768+
}
769+
670770
/**
671771
* Remove the comments from a json like text.
672772
* Comments can be single line comments (starting with # or //) or multiline comments using / * * /

src/compiler/emitter.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5311,6 +5311,21 @@ const _super = (function (geti, seti) {
53115311
emitSignatureParameters(ctor);
53125312
}
53135313
else {
5314+
// The ES2015 spec specifies in 14.5.14. Runtime Semantics: ClassDefinitionEvaluation:
5315+
// If constructor is empty, then
5316+
// If ClassHeritag_eopt is present and protoParent is not null, then
5317+
// Let constructor be the result of parsing the source text
5318+
// constructor(...args) { super (...args);}
5319+
// using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
5320+
// Else,
5321+
// Let constructor be the result of parsing the source text
5322+
// constructor( ){ }
5323+
// using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
5324+
//
5325+
// While we could emit the '...args' rest parameter, certain later tools in the pipeline might
5326+
// downlevel the '...args' portion less efficiently by naively copying the contents of 'arguments' to an array.
5327+
// Instead, we'll avoid using a rest parameter and spread into the super call as
5328+
// 'super(...arguments)' instead of 'super(...args)', as you can see below.
53145329
write("()");
53155330
}
53165331
}
@@ -5349,6 +5364,7 @@ const _super = (function (geti, seti) {
53495364
write("_super.apply(this, arguments);");
53505365
}
53515366
else {
5367+
// See comment above on using '...arguments' instead of '...args'.
53525368
write("super(...arguments);");
53535369
}
53545370
emitEnd(baseTypeElement);

src/compiler/program.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,6 @@ namespace ts {
828828
: { resolvedModule: undefined, failedLookupLocations };
829829
}
830830

831-
/* @internal */
832-
export const defaultInitCompilerOptions: CompilerOptions = {
833-
module: ModuleKind.CommonJS,
834-
target: ScriptTarget.ES5,
835-
noImplicitAny: false,
836-
sourceMap: false,
837-
};
838-
839831
interface OutputFingerprint {
840832
hash: string;
841833
byteOrderMark: boolean;

src/compiler/tsc.ts

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -763,67 +763,11 @@ namespace ts {
763763
reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file), /* host */ undefined);
764764
}
765765
else {
766-
const compilerOptions = extend(options, defaultInitCompilerOptions);
767-
const configurations: any = {
768-
compilerOptions: serializeCompilerOptions(compilerOptions)
769-
};
770-
771-
if (fileNames && fileNames.length) {
772-
// only set the files property if we have at least one file
773-
configurations.files = fileNames;
774-
}
775-
else {
776-
configurations.exclude = ["node_modules"];
777-
if (compilerOptions.outDir) {
778-
configurations.exclude.push(compilerOptions.outDir);
779-
}
780-
}
781-
782-
sys.writeFile(file, JSON.stringify(configurations, undefined, 4));
766+
sys.writeFile(file, JSON.stringify(generateTSConfig(options, fileNames), undefined, 4));
783767
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* host */ undefined);
784768
}
785769

786770
return;
787-
788-
function serializeCompilerOptions(options: CompilerOptions): Map<string | number | boolean> {
789-
const result = createMap<string | number | boolean>();
790-
const optionsNameMap = getOptionNameMap().optionNameMap;
791-
792-
for (const name in options) {
793-
if (hasProperty(options, name)) {
794-
// tsconfig only options cannot be specified via command line,
795-
// so we can assume that only types that can appear here string | number | boolean
796-
const value = <string | number | boolean>options[name];
797-
switch (name) {
798-
case "init":
799-
case "watch":
800-
case "version":
801-
case "help":
802-
case "project":
803-
break;
804-
default:
805-
let optionDefinition = optionsNameMap[name.toLowerCase()];
806-
if (optionDefinition) {
807-
if (typeof optionDefinition.type === "string") {
808-
// string, number or boolean
809-
result[name] = value;
810-
}
811-
else {
812-
// Enum
813-
const typeMap = <Map<number>>optionDefinition.type;
814-
for (const key in typeMap) {
815-
if (typeMap[key] === value) {
816-
result[name] = key;
817-
}
818-
}
819-
}
820-
}
821-
break;
822-
}
823-
}
824-
}
825-
return result;
826-
}
827771
}
828772
}
829773

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ namespace ts {
27672767

27682768
/* @internal */
27692769
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
2770-
type: Map<number | string>; // an object literal mapping named values to actual values
2770+
type: Map<number | string>; // an object literal mapping named values to actual values
27712771
}
27722772

27732773
/* @internal */

src/harness/harness.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,17 +1673,18 @@ namespace Harness {
16731673
const encoded_actual = Utils.encodeString(actual);
16741674
if (expected !== encoded_actual) {
16751675
if (actual === NoContent) {
1676-
IO.writeFile(relativeFileName + ".delete", "");
1676+
IO.writeFile(localPath(relativeFileName + ".delete"), "");
16771677
}
16781678
else {
1679-
IO.writeFile(relativeFileName, actual);
1679+
IO.writeFile(localPath(relativeFileName), actual);
16801680
}
16811681
// Overwrite & issue error
16821682
const errMsg = "The baseline file " + relativeFileName + " has changed.";
16831683
throw new Error(errMsg);
16841684
}
16851685
}
16861686

1687+
16871688
export function runBaseline(
16881689
descriptionForDescribe: string,
16891690
relativeFileName: string,

src/harness/rwcRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ namespace RWC {
198198
}
199199
// Do not include the library in the baselines to avoid noise
200200
const baselineFiles = inputFiles.concat(otherFiles).filter(f => !Harness.isDefaultLibraryFile(f.unitName));
201-
return Harness.Compiler.getErrorBaseline(baselineFiles, compilerResult.errors);
201+
const errors = compilerResult.errors.filter(e => !Harness.isDefaultLibraryFile(e.file.fileName));
202+
return Harness.Compiler.getErrorBaseline(baselineFiles, errors);
202203
}, false, baselineOpts);
203204
});
204205

src/harness/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"./unittests/convertCompilerOptionsFromJson.ts",
9090
"./unittests/convertTypingOptionsFromJson.ts",
9191
"./unittests/tsserverProjectSystem.ts",
92-
"./unittests/matchFiles.ts"
92+
"./unittests/matchFiles.ts",
93+
"./unittests/initializeTSConfig.ts"
9394
]
9495
}

0 commit comments

Comments
 (0)