Skip to content

Commit

Permalink
Merge branch 'master' into map4
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Oct 27, 2016
2 parents c958c47 + f307948 commit dec5f4b
Show file tree
Hide file tree
Showing 497 changed files with 5,084 additions and 3,073 deletions.
12 changes: 6 additions & 6 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ var compilerSources = [
"visitor.ts",
"transformers/destructuring.ts",
"transformers/ts.ts",
"transformers/module/es2015.ts",
"transformers/module/system.ts",
"transformers/module/module.ts",
"transformers/jsx.ts",
"transformers/es2017.ts",
"transformers/es2016.ts",
"transformers/es2015.ts",
"transformers/generators.ts",
"transformers/es5.ts",
"transformers/module/es2015.ts",
"transformers/module/system.ts",
"transformers/module/module.ts",
"transformer.ts",
"sourcemap.ts",
"comments.ts",
Expand Down Expand Up @@ -108,15 +108,15 @@ var servicesSources = [
"visitor.ts",
"transformers/destructuring.ts",
"transformers/ts.ts",
"transformers/module/es2015.ts",
"transformers/module/system.ts",
"transformers/module/module.ts",
"transformers/jsx.ts",
"transformers/es2017.ts",
"transformers/es2016.ts",
"transformers/es2015.ts",
"transformers/generators.ts",
"transformers/es5.ts",
"transformers/module/es2015.ts",
"transformers/module/system.ts",
"transformers/module/module.ts",
"transformer.ts",
"sourcemap.ts",
"comments.ts",
Expand Down
23 changes: 4 additions & 19 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2534,7 +2534,7 @@ namespace ts {
&& (leftKind === SyntaxKind.ObjectLiteralExpression
|| leftKind === SyntaxKind.ArrayLiteralExpression)) {
// Destructuring assignments are ES6 syntax.
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.DestructuringAssignment;
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
}
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
|| operatorTokenKind === SyntaxKind.AsteriskAsteriskEqualsToken) {
Expand Down Expand Up @@ -2615,9 +2615,9 @@ namespace ts {

// A class with a parameter property assignment, property initializer, or decorator is
// TypeScript syntax.
// An exported declaration may be TypeScript syntax.
// An exported declaration may be TypeScript syntax, but is handled by the visitor
// for a namespace declaration.
if ((subtreeFlags & TransformFlags.TypeScriptClassSyntaxMask)
|| (modifierFlags & ModifierFlags.Export)
|| node.typeParameters) {
transformFlags |= TransformFlags.AssertTypeScript;
}
Expand Down Expand Up @@ -2787,11 +2787,6 @@ namespace ts {
else {
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion;

// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
if (modifierFlags & ModifierFlags.Export) {
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2015;
}

// TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
// syntax.
if (modifierFlags & ModifierFlags.TypeScriptModifier
Expand Down Expand Up @@ -2933,11 +2928,6 @@ namespace ts {
else {
transformFlags = subtreeFlags;

// If a VariableStatement is exported, then it is either ES6 or TypeScript syntax.
if (modifierFlags & ModifierFlags.Export) {
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
}

if (declarationListTransformFlags & TransformFlags.ContainsBindingPattern) {
transformFlags |= TransformFlags.AssertES2015;
}
Expand Down Expand Up @@ -3054,12 +3044,6 @@ namespace ts {
transformFlags |= TransformFlags.AssertJsx;
break;

case SyntaxKind.ExportKeyword:
// This node is both ES6 and TypeScript syntax.
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
break;

case SyntaxKind.DefaultKeyword:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.TemplateHead:
case SyntaxKind.TemplateMiddle:
Expand All @@ -3068,6 +3052,7 @@ namespace ts {
case SyntaxKind.TaggedTemplateExpression:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.ForOfStatement:
case SyntaxKind.StaticKeyword:
// These nodes are ES6 syntax.
transformFlags |= TransformFlags.AssertES2015;
break;
Expand Down
22 changes: 16 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,8 @@ namespace ts {
}

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

if (moduleNotFoundError) {
// report errors only if it was requested
const tsExtension = tryExtractTypeScriptExtension(moduleName);
if (tsExtension) {
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
if (resolutionDiagnostic) {
error(errorNode, resolutionDiagnostic, moduleName, resolvedModule.resolvedFileName);
}
else {
error(errorNode, moduleNotFoundError, moduleName);
const tsExtension = tryExtractTypeScriptExtension(moduleName);
if (tsExtension) {
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
}
else {
error(errorNode, moduleNotFoundError, moduleName);
}
}
}
return undefined;
Expand Down Expand Up @@ -19507,6 +19513,10 @@ namespace ts {
if (typeReferenceDirective) {
(typeReferenceDirectives || (typeReferenceDirectives = [])).push(typeReferenceDirective);
}
else {
// found at least one entry that does not originate from type reference directive
return undefined;
}
}
}
return typeReferenceDirectives;
Expand Down
107 changes: 84 additions & 23 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,16 @@ namespace ts {

export function some<T>(array: T[], predicate?: (value: T) => boolean): boolean {
if (array) {
for (const v of array) {
if (!predicate || predicate(v)) {
return true;
if (predicate) {
for (const v of array) {
if (predicate(v)) {
return true;
}
}
}
else {
return array.length > 0;
}
}
return false;
}
Expand Down Expand Up @@ -498,14 +503,35 @@ namespace ts {
return result;
}

export function addRange<T>(to: T[], from: T[]): void {
if (to && from) {
for (const v of from) {
if (v !== undefined) {
to.push(v);
}
}
/**
* Appends a value to an array, returning the array.
*
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
* is created if `value` was appended.
* @param value The value to append to the array. If `value` is `undefined`, nothing is
* appended.
*/
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
if (value === undefined) return to;
if (to === undefined) to = [];
to.push(value);
return to;
}

/**
* Appends a range of value to an array, returning the array.
*
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
* is created if `value` was appended.
* @param from The values to append to the array. If `from` is `undefined`, nothing is
* appended. If an element of `from` is `undefined`, that element is not appended.
*/
export function addRange<T>(to: T[] | undefined, from: T[] | undefined): T[] | undefined {
if (from === undefined) return to;
for (const v of from) {
to = append(to, v);
}
return to;
}

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

/**
* Returns the first element of an array if non-empty, `undefined` otherwise.
*/
export function firstOrUndefined<T>(array: T[]): T {
return array && array.length > 0
? array[0]
: undefined;
}

/**
* Returns the last element of an array if non-empty, `undefined` otherwise.
*/
export function lastOrUndefined<T>(array: T[]): T {
return array && array.length > 0
? array[array.length - 1]
: undefined;
}

/**
* Returns the only element of an array if it contains only one element, `undefined` otherwise.
*/
export function singleOrUndefined<T>(array: T[]): T {
return array && array.length === 1
? array[0]
: undefined;
}

/**
* Returns the only element of an array if it contains only one element; otheriwse, returns the
* array.
*/
export function singleOrMany<T>(array: T[]): T | T[] {
return array && array.length === 1
? array[0]
: array;
}

/**
* Returns the last element of an array if non-empty, undefined otherwise.
*/
export function lastOrUndefined<T>(array: T[]): T {
return array && array.length > 0
? array[array.length - 1]
: undefined;
}

export function replaceElement<T>(array: T[], index: number, value: T): T[] {
const result = array.slice(0);
result[index] = value;
Expand Down Expand Up @@ -1641,10 +1677,6 @@ namespace ts {
return path.substring(0, path.length - extension.length);
}

export function isJsxOrTsxExtension(ext: string): boolean {
return ext === ".jsx" || ext === ".tsx";
}

export function changeExtension<T extends string | Path>(path: T, newExtension: string): T {
return <T>(removeFileExtension(path) + newExtension);
}
Expand Down Expand Up @@ -1837,4 +1869,33 @@ namespace ts {
// pos === undefined || pos === null || isNaN(pos) || pos < 0;
return !(pos >= 0);
}

/** True if an extension is one of the supported TypeScript extensions. */
export function extensionIsTypeScript(ext: Extension): boolean {
return ext <= Extension.LastTypeScriptExtension;
}

/**
* Gets the extension from a path.
* Path must have a valid extension.
*/
export function extensionFromPath(path: string): Extension {
if (fileExtensionIs(path, ".d.ts")) {
return Extension.Dts;
}
if (fileExtensionIs(path, ".ts")) {
return Extension.Ts;
}
if (fileExtensionIs(path, ".tsx")) {
return Extension.Tsx;
}
if (fileExtensionIs(path, ".js")) {
return Extension.Js;
}
if (fileExtensionIs(path, ".jsx")) {
return Extension.Jsx;
}
Debug.fail(`File ${path} has unknown extension.`);
return Extension.Js;
}
}
12 changes: 10 additions & 2 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@
"category": "Message",
"code": 6099
},
"'package.json' does not have 'types' field.": {
"'package.json' does not have a 'types' or 'main' field.": {
"category": "Message",
"code": 6100
},
Expand Down Expand Up @@ -2841,7 +2841,7 @@
"category": "Message",
"code": 6136
},
"No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'": {
"No types specified in 'package.json', so returning 'main' value of '{0}'": {
"category": "Message",
"code": 6137
},
Expand All @@ -2861,6 +2861,14 @@
"category": "Message",
"code": 6141
},
"Module '{0}' was resolved to '{1}', but '--jsx' is not set.": {
"category": "Error",
"code": 6142
},
"Module '{0}' was resolved to '{1}', but '--allowJs' is not set.": {
"category": "Error",
"code": 6143
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down
Loading

0 comments on commit dec5f4b

Please sign in to comment.