Skip to content

Commit 2f476bf

Browse files
author
Yui T
committed
Merge branch 'master' into master-dynamicImport
2 parents 769f6ad + b62e1b5 commit 2f476bf

File tree

310 files changed

+8287
-3250
lines changed

Some content is hidden

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

310 files changed

+8287
-3250
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ branches:
2121
- release-2.3
2222

2323
install:
24-
- npm uninstall typescript
25-
- npm uninstall tslint
24+
- npm uninstall typescript --no-save
25+
- npm uninstall tslint --no-save
2626
- npm install
2727

2828
cache:

Jakefile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var harnessSources = harnessCoreSources.concat([
129129
"initializeTSConfig.ts",
130130
"printer.ts",
131131
"textChanges.ts",
132+
"telemetry.ts",
132133
"transform.ts",
133134
"customTransforms.ts",
134135
].map(function (f) {
@@ -1079,7 +1080,7 @@ var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js';
10791080
file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function () {
10801081
var temp = builtLocalDirectory + 'temp';
10811082
jake.mkdirP(temp);
1082-
var options = "--types --outdir " + temp + ' ' + loggedIOpath;
1083+
var options = "--target es5 --lib es6 --types --outdir " + temp + ' ' + loggedIOpath;
10831084
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " ";
10841085
console.log(cmd + "\n");
10851086
var ex = jake.createExec([cmd]);
@@ -1093,7 +1094,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function () {
10931094

10941095
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
10951096
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js';
1096-
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true);
1097+
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true, { lib: "es6", types: ["node"] });
10971098

10981099
desc("Builds an instrumented tsc.js");
10991100
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function () {

jenkins.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
# Set up NVM
44
export NVM_DIR="/home/dotnet-bot/.nvm"
5-
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
5+
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
66

77
nvm install $1
88

9-
npm uninstall typescript
10-
npm uninstall tslint
9+
npm uninstall typescript --no-save
10+
npm uninstall tslint --no-save
1111
npm install
1212
npm update
1313
npm test

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"gulp-insert": "latest",
6060
"gulp-newer": "latest",
6161
"gulp-sourcemaps": "latest",
62-
"gulp-typescript": "3.1.5",
62+
"gulp-typescript": "latest",
6363
"into-stream": "latest",
6464
"istanbul": "latest",
6565
"jake": "latest",
@@ -74,7 +74,7 @@
7474
"through2": "latest",
7575
"travis-fold": "latest",
7676
"ts-node": "latest",
77-
"tslint": "next",
77+
"tslint": "latest",
7878
"typescript": "next"
7979
},
8080
"scripts": {

src/compiler/binder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,10 @@ namespace ts {
21782178
case SyntaxKind.JSDocRecordMember:
21792179
return bindPropertyWorker(node as JSDocRecordMember);
21802180
case SyntaxKind.JSDocPropertyTag:
2181-
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
2181+
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag,
2182+
(node as JSDocPropertyTag).isBracketed || ((node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType) ?
2183+
SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property,
2184+
SymbolFlags.PropertyExcludes);
21822185
case SyntaxKind.JSDocFunctionType:
21832186
return bindFunctionOrConstructorType(<SignatureDeclaration>node);
21842187
case SyntaxKind.JSDocTypeLiteral:
@@ -3597,4 +3600,4 @@ namespace ts {
35973600
return TransformFlags.NodeExcludes;
35983601
}
35993602
}
3600-
}
3603+
}

src/compiler/checker.ts

Lines changed: 223 additions & 199 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ namespace ts {
693693
return typeAcquisition;
694694
}
695695

696-
/* @internal */
697-
export function getOptionNameMap(): OptionNameMap {
696+
function getOptionNameMap(): OptionNameMap {
698697
if (optionNameMapCache) {
699698
return optionNameMapCache;
700699
}
@@ -747,7 +746,6 @@ namespace ts {
747746
const options: CompilerOptions = {};
748747
const fileNames: string[] = [];
749748
const errors: Diagnostic[] = [];
750-
const { optionNameMap, shortOptionNames } = getOptionNameMap();
751749

752750
parseStrings(commandLine);
753751
return {
@@ -759,21 +757,13 @@ namespace ts {
759757
function parseStrings(args: string[]) {
760758
let i = 0;
761759
while (i < args.length) {
762-
let s = args[i];
760+
const s = args[i];
763761
i++;
764762
if (s.charCodeAt(0) === CharacterCodes.at) {
765763
parseResponseFile(s.slice(1));
766764
}
767765
else if (s.charCodeAt(0) === CharacterCodes.minus) {
768-
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
769-
770-
// Try to translate short option names to their full equivalents.
771-
const short = shortOptionNames.get(s);
772-
if (short !== undefined) {
773-
s = short;
774-
}
775-
776-
const opt = optionNameMap.get(s);
766+
const opt = getOptionFromName(s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1), /*allowShort*/ true);
777767
if (opt) {
778768
if (opt.isTSConfigOnly) {
779769
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name));
@@ -861,6 +851,19 @@ namespace ts {
861851
}
862852
}
863853

854+
function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
855+
optionName = optionName.toLowerCase();
856+
const { optionNameMap, shortOptionNames } = getOptionNameMap();
857+
// Try to translate short option names to their full equivalents.
858+
if (allowShort) {
859+
const short = shortOptionNames.get(optionName);
860+
if (short !== undefined) {
861+
optionName = short;
862+
}
863+
}
864+
return optionNameMap.get(optionName);
865+
}
866+
864867
/**
865868
* Read tsconfig.json file
866869
* @param fileName The path to the config file
@@ -1040,7 +1043,7 @@ namespace ts {
10401043
for (let i = 0; i < nameColumn.length; i++) {
10411044
const optionName = nameColumn[i];
10421045
const description = descriptionColumn[i];
1043-
result.push(tab + tab + optionName + makePadding(marginLength - optionName.length + 2) + description);
1046+
result.push(optionName && `${tab}${tab}${optionName}${ description && (makePadding(marginLength - optionName.length + 2) + description)}`);
10441047
}
10451048
if (configurations.files && configurations.files.length) {
10461049
result.push(`${tab}},`);
@@ -1706,4 +1709,42 @@ namespace ts {
17061709
function caseInsensitiveKeyMapper(key: string) {
17071710
return key.toLowerCase();
17081711
}
1712+
1713+
/**
1714+
* Produces a cleaned version of compiler options with personally identifiying info (aka, paths) removed.
1715+
* Also converts enum values back to strings.
1716+
*/
1717+
/* @internal */
1718+
export function convertCompilerOptionsForTelemetry(opts: ts.CompilerOptions): ts.CompilerOptions {
1719+
const out: ts.CompilerOptions = {};
1720+
for (const key in opts) if (opts.hasOwnProperty(key)) {
1721+
const type = getOptionFromName(key);
1722+
if (type !== undefined) { // Ignore unknown options
1723+
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
1724+
}
1725+
}
1726+
return out;
1727+
}
1728+
1729+
function getOptionValueWithEmptyStrings(value: any, option: CommandLineOption): {} {
1730+
switch (option.type) {
1731+
case "object": // "paths". Can't get any useful information from the value since we blank out strings, so just return "".
1732+
return "";
1733+
case "string": // Could be any arbitrary string -- use empty string instead.
1734+
return "";
1735+
case "number": // Allow numbers, but be sure to check it's actually a number.
1736+
return typeof value === "number" ? value : "";
1737+
case "boolean":
1738+
return typeof value === "boolean" ? value : "";
1739+
case "list":
1740+
const elementType = (option as CommandLineOptionOfListType).element;
1741+
return ts.isArray(value) ? value.map(v => getOptionValueWithEmptyStrings(v, elementType)) : "";
1742+
default:
1743+
return ts.forEachEntry(option.type, (optionEnumValue, optionStringValue) => {
1744+
if (optionEnumValue === value) {
1745+
return optionStringValue;
1746+
}
1747+
});
1748+
}
1749+
}
17091750
}

src/compiler/core.ts

Lines changed: 89 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,18 @@ namespace ts {
521521
return result || array;
522522
}
523523

524+
export function mapDefined<T>(array: ReadonlyArray<T>, mapFn: (x: T, i: number) => T | undefined): ReadonlyArray<T> {
525+
const result: T[] = [];
526+
for (let i = 0; i < array.length; i++) {
527+
const item = array[i];
528+
const mapped = mapFn(item, i);
529+
if (mapped !== undefined) {
530+
result.push(mapped);
531+
}
532+
}
533+
return result;
534+
}
535+
524536
/**
525537
* Computes the first matching span of elements and returns a tuple of the first span
526538
* and the remaining elements.
@@ -740,18 +752,34 @@ namespace ts {
740752
return to;
741753
}
742754

755+
/**
756+
* Gets the actual offset into an array for a relative offset. Negative offsets indicate a
757+
* position offset from the end of the array.
758+
*/
759+
function toOffset(array: any[], offset: number) {
760+
return offset < 0 ? array.length + offset : offset;
761+
}
762+
743763
/**
744764
* Appends a range of value to an array, returning the array.
745765
*
746766
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
747767
* is created if `value` was appended.
748768
* @param from The values to append to the array. If `from` is `undefined`, nothing is
749769
* appended. If an element of `from` is `undefined`, that element is not appended.
770+
* @param start The offset in `from` at which to start copying values.
771+
* @param end The offset in `from` at which to stop copying values (non-inclusive).
750772
*/
751-
export function addRange<T>(to: T[] | undefined, from: T[] | undefined): T[] | undefined {
773+
export function addRange<T>(to: T[] | undefined, from: T[] | undefined, start?: number, end?: number): T[] | undefined {
752774
if (from === undefined) return to;
753-
for (const v of from) {
754-
to = append(to, v);
775+
if (to === undefined) return from.slice(start, end);
776+
start = start === undefined ? 0 : toOffset(from, start);
777+
end = end === undefined ? from.length : toOffset(from, end);
778+
for (let i = start; i < end && i < from.length; i++) {
779+
const v = from[i];
780+
if (v !== undefined) {
781+
to.push(from[i]);
782+
}
755783
}
756784
return to;
757785
}
@@ -776,28 +804,38 @@ namespace ts {
776804
return true;
777805
}
778806

807+
/**
808+
* Returns the element at a specific offset in an array if non-empty, `undefined` otherwise.
809+
* A negative offset indicates the element should be retrieved from the end of the array.
810+
*/
811+
export function elementAt<T>(array: T[] | undefined, offset: number): T | undefined {
812+
if (array) {
813+
offset = toOffset(array, offset);
814+
if (offset < array.length) {
815+
return array[offset];
816+
}
817+
}
818+
return undefined;
819+
}
820+
779821
/**
780822
* Returns the first element of an array if non-empty, `undefined` otherwise.
781823
*/
782-
export function firstOrUndefined<T>(array: T[]): T {
783-
return array && array.length > 0
784-
? array[0]
785-
: undefined;
824+
export function firstOrUndefined<T>(array: T[]): T | undefined {
825+
return elementAt(array, 0);
786826
}
787827

788828
/**
789829
* Returns the last element of an array if non-empty, `undefined` otherwise.
790830
*/
791-
export function lastOrUndefined<T>(array: T[]): T {
792-
return array && array.length > 0
793-
? array[array.length - 1]
794-
: undefined;
831+
export function lastOrUndefined<T>(array: T[]): T | undefined {
832+
return elementAt(array, -1);
795833
}
796834

797835
/**
798836
* Returns the only element of an array if it contains only one element, `undefined` otherwise.
799837
*/
800-
export function singleOrUndefined<T>(array: T[]): T {
838+
export function singleOrUndefined<T>(array: T[]): T | undefined {
801839
return array && array.length === 1
802840
? array[0]
803841
: undefined;
@@ -1125,6 +1163,15 @@ namespace ts {
11251163
return Array.isArray ? Array.isArray(value) : value instanceof Array;
11261164
}
11271165

1166+
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
1167+
return value !== undefined && test(value) ? value : undefined;
1168+
}
1169+
1170+
export function cast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut {
1171+
if (value !== undefined && test(value)) return value;
1172+
Debug.fail(`Invalid cast. The supplied value did not pass the test '${Debug.getFunctionName(test)}'.`);
1173+
}
1174+
11281175
/** Does nothing. */
11291176
export function noop(): void {}
11301177

@@ -2210,8 +2257,11 @@ namespace ts {
22102257
this.declarations = undefined;
22112258
}
22122259

2213-
function Type(this: Type, _checker: TypeChecker, flags: TypeFlags) {
2260+
function Type(this: Type, checker: TypeChecker, flags: TypeFlags) {
22142261
this.flags = flags;
2262+
if (Debug.isDebugging) {
2263+
this.checker = checker;
2264+
}
22152265
}
22162266

22172267
function Signature() {
@@ -2248,24 +2298,42 @@ namespace ts {
22482298

22492299
export namespace Debug {
22502300
export let currentAssertionLevel = AssertionLevel.None;
2301+
export let isDebugging = false;
22512302

22522303
export function shouldAssert(level: AssertionLevel): boolean {
22532304
return currentAssertionLevel >= level;
22542305
}
22552306

2256-
export function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void {
2307+
export function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string, stackCrawlMark?: Function): void {
22572308
if (!expression) {
2258-
let verboseDebugString = "";
22592309
if (verboseDebugInfo) {
2260-
verboseDebugString = "\r\nVerbose Debug Information: " + verboseDebugInfo();
2310+
message += "\r\nVerbose Debug Information: " + verboseDebugInfo();
22612311
}
2262-
debugger;
2263-
throw new Error("Debug Failure. False expression: " + (message || "") + verboseDebugString);
2312+
fail(message ? "False expression: " + message : "False expression.", stackCrawlMark || assert);
22642313
}
22652314
}
22662315

2267-
export function fail(message?: string): void {
2268-
Debug.assert(/*expression*/ false, message);
2316+
export function fail(message?: string, stackCrawlMark?: Function): void {
2317+
debugger;
2318+
const e = new Error(message ? `Debug Failure. ` : "Debug Failure.");
2319+
if ((<any>Error).captureStackTrace) {
2320+
(<any>Error).captureStackTrace(e, stackCrawlMark || fail);
2321+
}
2322+
throw e;
2323+
}
2324+
2325+
export function getFunctionName(func: Function) {
2326+
if (typeof func !== "function") {
2327+
return "";
2328+
}
2329+
else if (func.hasOwnProperty("name")) {
2330+
return (<any>func).name;
2331+
}
2332+
else {
2333+
const text = Function.prototype.toString.call(func);
2334+
const match = /^function\s+([\w\$]+)\s*\(/.exec(text);
2335+
return match ? match[1] : "";
2336+
}
22692337
}
22702338
}
22712339

@@ -2431,4 +2499,4 @@ namespace ts {
24312499
export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
24322500
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
24332501
}
2434-
}
2502+
}

0 commit comments

Comments
 (0)