Skip to content

Commit dec5f4b

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map4
2 parents c958c47 + f307948 commit dec5f4b

File tree

497 files changed

+5084
-3073
lines changed

Some content is hidden

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

497 files changed

+5084
-3073
lines changed

Jakefile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ var compilerSources = [
7171
"visitor.ts",
7272
"transformers/destructuring.ts",
7373
"transformers/ts.ts",
74-
"transformers/module/es2015.ts",
75-
"transformers/module/system.ts",
76-
"transformers/module/module.ts",
7774
"transformers/jsx.ts",
7875
"transformers/es2017.ts",
7976
"transformers/es2016.ts",
8077
"transformers/es2015.ts",
8178
"transformers/generators.ts",
8279
"transformers/es5.ts",
80+
"transformers/module/es2015.ts",
81+
"transformers/module/system.ts",
82+
"transformers/module/module.ts",
8383
"transformer.ts",
8484
"sourcemap.ts",
8585
"comments.ts",
@@ -108,15 +108,15 @@ var servicesSources = [
108108
"visitor.ts",
109109
"transformers/destructuring.ts",
110110
"transformers/ts.ts",
111-
"transformers/module/es2015.ts",
112-
"transformers/module/system.ts",
113-
"transformers/module/module.ts",
114111
"transformers/jsx.ts",
115112
"transformers/es2017.ts",
116113
"transformers/es2016.ts",
117114
"transformers/es2015.ts",
118115
"transformers/generators.ts",
119116
"transformers/es5.ts",
117+
"transformers/module/es2015.ts",
118+
"transformers/module/system.ts",
119+
"transformers/module/module.ts",
120120
"transformer.ts",
121121
"sourcemap.ts",
122122
"comments.ts",

src/compiler/binder.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ namespace ts {
25342534
&& (leftKind === SyntaxKind.ObjectLiteralExpression
25352535
|| leftKind === SyntaxKind.ArrayLiteralExpression)) {
25362536
// Destructuring assignments are ES6 syntax.
2537-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.DestructuringAssignment;
2537+
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
25382538
}
25392539
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
25402540
|| operatorTokenKind === SyntaxKind.AsteriskAsteriskEqualsToken) {
@@ -2615,9 +2615,9 @@ namespace ts {
26152615

26162616
// A class with a parameter property assignment, property initializer, or decorator is
26172617
// TypeScript syntax.
2618-
// An exported declaration may be TypeScript syntax.
2618+
// An exported declaration may be TypeScript syntax, but is handled by the visitor
2619+
// for a namespace declaration.
26192620
if ((subtreeFlags & TransformFlags.TypeScriptClassSyntaxMask)
2620-
|| (modifierFlags & ModifierFlags.Export)
26212621
|| node.typeParameters) {
26222622
transformFlags |= TransformFlags.AssertTypeScript;
26232623
}
@@ -2787,11 +2787,6 @@ namespace ts {
27872787
else {
27882788
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion;
27892789

2790-
// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
2791-
if (modifierFlags & ModifierFlags.Export) {
2792-
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2015;
2793-
}
2794-
27952790
// TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
27962791
// syntax.
27972792
if (modifierFlags & ModifierFlags.TypeScriptModifier
@@ -2933,11 +2928,6 @@ namespace ts {
29332928
else {
29342929
transformFlags = subtreeFlags;
29352930

2936-
// If a VariableStatement is exported, then it is either ES6 or TypeScript syntax.
2937-
if (modifierFlags & ModifierFlags.Export) {
2938-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
2939-
}
2940-
29412931
if (declarationListTransformFlags & TransformFlags.ContainsBindingPattern) {
29422932
transformFlags |= TransformFlags.AssertES2015;
29432933
}
@@ -3054,12 +3044,6 @@ namespace ts {
30543044
transformFlags |= TransformFlags.AssertJsx;
30553045
break;
30563046

3057-
case SyntaxKind.ExportKeyword:
3058-
// This node is both ES6 and TypeScript syntax.
3059-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
3060-
break;
3061-
3062-
case SyntaxKind.DefaultKeyword:
30633047
case SyntaxKind.NoSubstitutionTemplateLiteral:
30643048
case SyntaxKind.TemplateHead:
30653049
case SyntaxKind.TemplateMiddle:
@@ -3068,6 +3052,7 @@ namespace ts {
30683052
case SyntaxKind.TaggedTemplateExpression:
30693053
case SyntaxKind.ShorthandPropertyAssignment:
30703054
case SyntaxKind.ForOfStatement:
3055+
case SyntaxKind.StaticKeyword:
30713056
// These nodes are ES6 syntax.
30723057
transformFlags |= TransformFlags.AssertES2015;
30733058
break;

src/compiler/checker.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,8 @@ namespace ts {
13801380
}
13811381

13821382
const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
1383-
const sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName);
1383+
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
1384+
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
13841385
if (sourceFile) {
13851386
if (sourceFile.symbol) {
13861387
// merged symbol is module declaration symbol combined with all augmentations
@@ -1402,13 +1403,18 @@ namespace ts {
14021403

14031404
if (moduleNotFoundError) {
14041405
// report errors only if it was requested
1405-
const tsExtension = tryExtractTypeScriptExtension(moduleName);
1406-
if (tsExtension) {
1407-
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
1408-
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
1406+
if (resolutionDiagnostic) {
1407+
error(errorNode, resolutionDiagnostic, moduleName, resolvedModule.resolvedFileName);
14091408
}
14101409
else {
1411-
error(errorNode, moduleNotFoundError, moduleName);
1410+
const tsExtension = tryExtractTypeScriptExtension(moduleName);
1411+
if (tsExtension) {
1412+
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
1413+
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
1414+
}
1415+
else {
1416+
error(errorNode, moduleNotFoundError, moduleName);
1417+
}
14121418
}
14131419
}
14141420
return undefined;
@@ -19507,6 +19513,10 @@ namespace ts {
1950719513
if (typeReferenceDirective) {
1950819514
(typeReferenceDirectives || (typeReferenceDirectives = [])).push(typeReferenceDirective);
1950919515
}
19516+
else {
19517+
// found at least one entry that does not originate from type reference directive
19518+
return undefined;
19519+
}
1951019520
}
1951119521
}
1951219522
return typeReferenceDirectives;

src/compiler/core.ts

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,16 @@ namespace ts {
399399

400400
export function some<T>(array: T[], predicate?: (value: T) => boolean): boolean {
401401
if (array) {
402-
for (const v of array) {
403-
if (!predicate || predicate(v)) {
404-
return true;
402+
if (predicate) {
403+
for (const v of array) {
404+
if (predicate(v)) {
405+
return true;
406+
}
405407
}
406408
}
409+
else {
410+
return array.length > 0;
411+
}
407412
}
408413
return false;
409414
}
@@ -498,14 +503,35 @@ namespace ts {
498503
return result;
499504
}
500505

501-
export function addRange<T>(to: T[], from: T[]): void {
502-
if (to && from) {
503-
for (const v of from) {
504-
if (v !== undefined) {
505-
to.push(v);
506-
}
507-
}
506+
/**
507+
* Appends a value to an array, returning the array.
508+
*
509+
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
510+
* is created if `value` was appended.
511+
* @param value The value to append to the array. If `value` is `undefined`, nothing is
512+
* appended.
513+
*/
514+
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
515+
if (value === undefined) return to;
516+
if (to === undefined) to = [];
517+
to.push(value);
518+
return to;
519+
}
520+
521+
/**
522+
* Appends a range of value to an array, returning the array.
523+
*
524+
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
525+
* is created if `value` was appended.
526+
* @param from The values to append to the array. If `from` is `undefined`, nothing is
527+
* appended. If an element of `from` is `undefined`, that element is not appended.
528+
*/
529+
export function addRange<T>(to: T[] | undefined, from: T[] | undefined): T[] | undefined {
530+
if (from === undefined) return to;
531+
for (const v of from) {
532+
to = append(to, v);
508533
}
534+
return to;
509535
}
510536

511537
export function rangeEquals<T>(array1: T[], array2: T[], pos: number, end: number) {
@@ -518,33 +544,43 @@ namespace ts {
518544
return true;
519545
}
520546

547+
/**
548+
* Returns the first element of an array if non-empty, `undefined` otherwise.
549+
*/
521550
export function firstOrUndefined<T>(array: T[]): T {
522551
return array && array.length > 0
523552
? array[0]
524553
: undefined;
525554
}
526555

556+
/**
557+
* Returns the last element of an array if non-empty, `undefined` otherwise.
558+
*/
559+
export function lastOrUndefined<T>(array: T[]): T {
560+
return array && array.length > 0
561+
? array[array.length - 1]
562+
: undefined;
563+
}
564+
565+
/**
566+
* Returns the only element of an array if it contains only one element, `undefined` otherwise.
567+
*/
527568
export function singleOrUndefined<T>(array: T[]): T {
528569
return array && array.length === 1
529570
? array[0]
530571
: undefined;
531572
}
532573

574+
/**
575+
* Returns the only element of an array if it contains only one element; otheriwse, returns the
576+
* array.
577+
*/
533578
export function singleOrMany<T>(array: T[]): T | T[] {
534579
return array && array.length === 1
535580
? array[0]
536581
: array;
537582
}
538583

539-
/**
540-
* Returns the last element of an array if non-empty, undefined otherwise.
541-
*/
542-
export function lastOrUndefined<T>(array: T[]): T {
543-
return array && array.length > 0
544-
? array[array.length - 1]
545-
: undefined;
546-
}
547-
548584
export function replaceElement<T>(array: T[], index: number, value: T): T[] {
549585
const result = array.slice(0);
550586
result[index] = value;
@@ -1641,10 +1677,6 @@ namespace ts {
16411677
return path.substring(0, path.length - extension.length);
16421678
}
16431679

1644-
export function isJsxOrTsxExtension(ext: string): boolean {
1645-
return ext === ".jsx" || ext === ".tsx";
1646-
}
1647-
16481680
export function changeExtension<T extends string | Path>(path: T, newExtension: string): T {
16491681
return <T>(removeFileExtension(path) + newExtension);
16501682
}
@@ -1837,4 +1869,33 @@ namespace ts {
18371869
// pos === undefined || pos === null || isNaN(pos) || pos < 0;
18381870
return !(pos >= 0);
18391871
}
1872+
1873+
/** True if an extension is one of the supported TypeScript extensions. */
1874+
export function extensionIsTypeScript(ext: Extension): boolean {
1875+
return ext <= Extension.LastTypeScriptExtension;
1876+
}
1877+
1878+
/**
1879+
* Gets the extension from a path.
1880+
* Path must have a valid extension.
1881+
*/
1882+
export function extensionFromPath(path: string): Extension {
1883+
if (fileExtensionIs(path, ".d.ts")) {
1884+
return Extension.Dts;
1885+
}
1886+
if (fileExtensionIs(path, ".ts")) {
1887+
return Extension.Ts;
1888+
}
1889+
if (fileExtensionIs(path, ".tsx")) {
1890+
return Extension.Tsx;
1891+
}
1892+
if (fileExtensionIs(path, ".js")) {
1893+
return Extension.Js;
1894+
}
1895+
if (fileExtensionIs(path, ".jsx")) {
1896+
return Extension.Jsx;
1897+
}
1898+
Debug.fail(`File ${path} has unknown extension.`);
1899+
return Extension.Js;
1900+
}
18401901
}

src/compiler/diagnosticMessages.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@
26932693
"category": "Message",
26942694
"code": 6099
26952695
},
2696-
"'package.json' does not have 'types' field.": {
2696+
"'package.json' does not have a 'types' or 'main' field.": {
26972697
"category": "Message",
26982698
"code": 6100
26992699
},
@@ -2841,7 +2841,7 @@
28412841
"category": "Message",
28422842
"code": 6136
28432843
},
2844-
"No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'": {
2844+
"No types specified in 'package.json', so returning 'main' value of '{0}'": {
28452845
"category": "Message",
28462846
"code": 6137
28472847
},
@@ -2861,6 +2861,14 @@
28612861
"category": "Message",
28622862
"code": 6141
28632863
},
2864+
"Module '{0}' was resolved to '{1}', but '--jsx' is not set.": {
2865+
"category": "Error",
2866+
"code": 6142
2867+
},
2868+
"Module '{0}' was resolved to '{1}', but '--allowJs' is not set.": {
2869+
"category": "Error",
2870+
"code": 6143
2871+
},
28642872
"Variable '{0}' implicitly has an '{1}' type.": {
28652873
"category": "Error",
28662874
"code": 7005

0 commit comments

Comments
 (0)