Skip to content

Commit bd1594f

Browse files
author
Andy Hanson
committed
Merge branch 'master' into applyCodeActionCommand_fileName
2 parents b873797 + bee12e6 commit bd1594f

File tree

95 files changed

+3352
-2016
lines changed

Some content is hidden

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

95 files changed

+3352
-2016
lines changed

.gitmodules

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[submodule "tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter"]
2+
path = tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
3+
url = https://github.com/Microsoft/TypeScript-React-Starter
4+
[submodule "tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter"]
5+
path = tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
6+
url = https://github.com/Microsoft/TypeScript-Node-Starter.git
7+
[submodule "tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter"]
8+
path = tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
9+
url = https://github.com/Microsoft/TypeScript-React-Native-Starter.git
10+
[submodule "tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter"]
11+
path = tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
12+
url = https://github.com/Microsoft/TypeScript-Vue-Starter.git
13+
[submodule "tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter"]
14+
path = tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
15+
url = https://github.com/Microsoft/TypeScript-WeChat-Starter.git

Jakefile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,10 @@ compileFile(word2mdJs,
731731
[word2mdTs],
732732
[word2mdTs],
733733
[],
734-
/*useBuiltCompiler*/ false);
734+
/*useBuiltCompiler*/ false,
735+
{
736+
lib: "scripthost,es5"
737+
});
735738

736739
// The generated spec.md; built for the 'generate-spec' task
737740
file(specMd, [word2mdJs, specWord], function () {

src/compiler/binder.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ namespace ts {
15701570
else {
15711571
let pattern: Pattern | undefined;
15721572
if (node.name.kind === SyntaxKind.StringLiteral) {
1573-
const text = (<StringLiteral>node.name).text;
1573+
const { text } = node.name;
15741574
if (hasZeroOrOneAsteriskCharacter(text)) {
15751575
pattern = tryParsePattern(text);
15761576
}
@@ -1589,22 +1589,13 @@ namespace ts {
15891589
else {
15901590
const state = declareModuleSymbol(node);
15911591
if (state !== ModuleInstanceState.NonInstantiated) {
1592-
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
1593-
// if module was already merged with some function, class or non-const enum
1594-
// treat is a non-const-enum-only
1595-
node.symbol.constEnumOnlyModule = false;
1596-
}
1597-
else {
1598-
const currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
1599-
if (node.symbol.constEnumOnlyModule === undefined) {
1600-
// non-merged case - use the current state
1601-
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
1602-
}
1603-
else {
1604-
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
1605-
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
1606-
}
1607-
}
1592+
const { symbol } = node;
1593+
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
1594+
symbol.constEnumOnlyModule = (!(symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)))
1595+
// Current must be `const enum` only
1596+
&& state === ModuleInstanceState.ConstEnumOnly
1597+
// Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
1598+
&& symbol.constEnumOnlyModule !== false;
16081599
}
16091600
}
16101601
}

src/compiler/checker.ts

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6454,7 +6454,10 @@ namespace ts {
64546454
}
64556455
for (let i = numTypeArguments; i < numTypeParameters; i++) {
64566456
const mapper = createTypeMapper(typeParameters, typeArguments);
6457-
const defaultType = getDefaultFromTypeParameter(typeParameters[i]);
6457+
let defaultType = getDefaultFromTypeParameter(typeParameters[i]);
6458+
if (defaultType && isTypeIdenticalTo(defaultType, emptyObjectType) && isJavaScriptImplicitAny) {
6459+
defaultType = anyType;
6460+
}
64586461
typeArguments[i] = defaultType ? instantiateType(defaultType, mapper) : getDefaultTypeArgumentType(isJavaScriptImplicitAny);
64596462
}
64606463
}
@@ -8907,7 +8910,9 @@ namespace ts {
89078910
if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) {
89088911
target = (<LiteralType>target).regularType;
89098912
}
8910-
if (source === target || relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) {
8913+
if (source === target ||
8914+
relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
8915+
relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) {
89118916
return true;
89128917
}
89138918
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
@@ -9050,7 +9055,8 @@ namespace ts {
90509055
return isIdenticalTo(source, target);
90519056
}
90529057

9053-
if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
9058+
if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
9059+
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
90549060

90559061
if (isObjectLiteralType(source) && source.flags & TypeFlags.FreshLiteral) {
90569062
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
@@ -10898,22 +10904,25 @@ namespace ts {
1089810904
// it as an inference candidate. Hopefully, a better candidate will come along that does
1089910905
// not contain anyFunctionType when we come back to this argument for its second round
1090010906
// of inference. Also, we exclude inferences for silentNeverType (which is used as a wildcard
10901-
// when constructing types from type parameters that had no inference candidates) and
10902-
// implicitNeverType (which is used as the element type for empty array literals).
10903-
if (source.flags & TypeFlags.ContainsAnyFunctionType || source === silentNeverType || source === implicitNeverType) {
10907+
// when constructing types from type parameters that had no inference candidates).
10908+
if (source.flags & TypeFlags.ContainsAnyFunctionType || source === silentNeverType) {
1090410909
return;
1090510910
}
1090610911
const inference = getInferenceInfoForType(target);
1090710912
if (inference) {
1090810913
if (!inference.isFixed) {
10909-
if (!inference.candidates || priority < inference.priority) {
10914+
// We give lowest priority to inferences of implicitNeverType (which is used as the
10915+
// element type for empty array literals). Thus, inferences from empty array literals
10916+
// only matter when no other inferences are made.
10917+
const p = priority | (source === implicitNeverType ? InferencePriority.NeverType : 0);
10918+
if (!inference.candidates || p < inference.priority) {
1091010919
inference.candidates = [source];
10911-
inference.priority = priority;
10920+
inference.priority = p;
1091210921
}
10913-
else if (priority === inference.priority) {
10922+
else if (p === inference.priority) {
1091410923
inference.candidates.push(source);
1091510924
}
10916-
if (!(priority & InferencePriority.ReturnType) && target.flags & TypeFlags.TypeParameter && !isTypeParameterAtTopLevel(originalTarget, <TypeParameter>target)) {
10925+
if (!(p & InferencePriority.ReturnType) && target.flags & TypeFlags.TypeParameter && !isTypeParameterAtTopLevel(originalTarget, <TypeParameter>target)) {
1091710926
inference.topLevel = false;
1091810927
}
1091910928
}
@@ -13463,10 +13472,14 @@ namespace ts {
1346313472
}
1346413473

1346513474
function isInParameterInitializerBeforeContainingFunction(node: Node) {
13475+
let inBindingInitializer = false;
1346613476
while (node.parent && !isFunctionLike(node.parent)) {
13467-
if (node.parent.kind === SyntaxKind.Parameter && (<ParameterDeclaration>node.parent).initializer === node) {
13477+
if (isParameter(node.parent) && (inBindingInitializer || node.parent.initializer === node)) {
1346813478
return true;
1346913479
}
13480+
if (isBindingElement(node.parent) && node.parent.initializer === node) {
13481+
inBindingInitializer = true;
13482+
}
1347013483

1347113484
node = node.parent;
1347213485
}
@@ -14191,7 +14204,7 @@ namespace ts {
1419114204
// type with those properties for which the binding pattern specifies a default value.
1419214205
if (contextualTypeHasPattern) {
1419314206
for (const prop of getPropertiesOfType(contextualType)) {
14194-
if (!propertiesTable.get(prop.escapedName)) {
14207+
if (!propertiesTable.get(prop.escapedName) && !(spread && getPropertyOfType(spread, prop.escapedName))) {
1419514208
if (!(prop.flags & SymbolFlags.Optional)) {
1419614209
error(prop.valueDeclaration || (<TransientSymbol>prop).bindingElement,
1419714210
Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
@@ -14372,19 +14385,7 @@ namespace ts {
1437214385
const parent = openingLikeElement.parent.kind === SyntaxKind.JsxElement ? openingLikeElement.parent as JsxElement : undefined;
1437314386
// We have to check that openingElement of the parent is the one we are visiting as this may not be true for selfClosingElement
1437414387
if (parent && parent.openingElement === openingLikeElement && parent.children.length > 0) {
14375-
const childrenTypes: Type[] = [];
14376-
for (const child of (parent as JsxElement).children) {
14377-
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
14378-
// because then type of children property will have constituent of string type.
14379-
if (child.kind === SyntaxKind.JsxText) {
14380-
if (!child.containsOnlyWhiteSpaces) {
14381-
childrenTypes.push(stringType);
14382-
}
14383-
}
14384-
else {
14385-
childrenTypes.push(checkExpression(child, checkMode));
14386-
}
14387-
}
14388+
const childrenTypes: Type[] = checkJsxChildren(parent as JsxElement, checkMode);
1438814389

1438914390
if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
1439014391
// Error if there is a attribute named "children" explicitly specified and children element.
@@ -14424,6 +14425,23 @@ namespace ts {
1442414425
}
1442514426
}
1442614427

14428+
function checkJsxChildren(node: JsxElement | JsxFragment, checkMode?: CheckMode) {
14429+
const childrenTypes: Type[] = [];
14430+
for (const child of node.children) {
14431+
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
14432+
// because then type of children property will have constituent of string type.
14433+
if (child.kind === SyntaxKind.JsxText) {
14434+
if (!child.containsOnlyWhiteSpaces) {
14435+
childrenTypes.push(stringType);
14436+
}
14437+
}
14438+
else {
14439+
childrenTypes.push(checkExpression(child, checkMode));
14440+
}
14441+
}
14442+
return childrenTypes;
14443+
}
14444+
1442714445
/**
1442814446
* Check attributes property of opening-like element. This function is called during chooseOverload to get call signature of a JSX opening-like element.
1442914447
* (See "checkApplicableSignatureForJsxOpeningLikeElement" for how the function is used)
@@ -14958,6 +14976,9 @@ namespace ts {
1495814976
if (isNodeOpeningLikeElement) {
1495914977
checkJsxAttributesAssignableToTagNameAttributes(<JsxOpeningLikeElement>node);
1496014978
}
14979+
else {
14980+
checkJsxChildren((node as JsxOpeningFragment).parent);
14981+
}
1496114982
}
1496214983

1496314984
/**
@@ -17158,7 +17179,7 @@ namespace ts {
1715817179
if (targetDeclarationKind !== SyntaxKind.Unknown) {
1715917180
const decl = getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
1716017181
// function/variable declaration should be ambient
17161-
return !!(decl.flags & NodeFlags.Ambient);
17182+
return !!decl && !!(decl.flags & NodeFlags.Ambient);
1716217183
}
1716317184
return false;
1716417185
}
@@ -22412,7 +22433,7 @@ namespace ts {
2241222433
const declaration = memberSymbol.valueDeclaration;
2241322434
if (declaration !== member) {
2241422435
if (isBlockScopedNameDeclaredBeforeUse(declaration, member)) {
22415-
return getNodeLinks(declaration).enumMemberValue;
22436+
return getEnumMemberValue(declaration as EnumMember);
2241622437
}
2241722438
error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
2241822439
return 0;

src/compiler/core.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ namespace ts {
6868
}
6969

7070
// The global Map object. This may not be available, so we must test for it.
71-
declare const Map: { new<T>(): Map<T> } | undefined;
71+
declare const Map: { new <T>(): Map<T> } | undefined;
7272
// Internet Explorer's Map doesn't support iteration, so don't use it.
7373
// tslint:disable-next-line no-in-operator variable-name
7474
const MapCtr = typeof Map !== "undefined" && "entries" in Map.prototype ? Map : shimMap();
7575

7676
// Keep the class inside a function so it doesn't get compiled if it's not used.
77-
function shimMap(): { new<T>(): Map<T> } {
77+
function shimMap(): { new <T>(): Map<T> } {
7878

7979
class MapIterator<T, U extends (string | T | [string, T])> {
8080
private data: MapLike<T>;
@@ -97,7 +97,7 @@ namespace ts {
9797
}
9898
}
9999

100-
return class<T> implements Map<T> {
100+
return class <T> implements Map<T> {
101101
private data = createDictionaryObject<T>();
102102
public size = 0;
103103

@@ -1324,6 +1324,10 @@ namespace ts {
13241324
return Array.isArray ? Array.isArray(value) : value instanceof Array;
13251325
}
13261326

1327+
export function toArray<T>(value: T | T[]): T[] {
1328+
return isArray(value) ? value : [value];
1329+
}
1330+
13271331
/**
13281332
* Tests whether a value is string
13291333
*/
@@ -2635,6 +2639,17 @@ namespace ts {
26352639
return <T>(removeFileExtension(path) + newExtension);
26362640
}
26372641

2642+
/**
2643+
* Takes a string like "jquery-min.4.2.3" and returns "jquery"
2644+
*/
2645+
export function removeMinAndVersionNumbers(fileName: string) {
2646+
// Match a "." or "-" followed by a version number or 'min' at the end of the name
2647+
const trailingMinOrVersion = /[.-]((min)|(\d+(\.\d+)*))$/;
2648+
2649+
// The "min" or version may both be present, in either order, so try applying the above twice.
2650+
return fileName.replace(trailingMinOrVersion, "").replace(trailingMinOrVersion, "");
2651+
}
2652+
26382653
export interface ObjectAllocator {
26392654
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
26402655
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
@@ -2835,7 +2850,7 @@ namespace ts {
28352850
return findBestPatternMatch(patterns, _ => _, candidate);
28362851
}
28372852

2838-
export function patternText({prefix, suffix}: Pattern): string {
2853+
export function patternText({ prefix, suffix }: Pattern): string {
28392854
return `${prefix}*${suffix}`;
28402855
}
28412856

@@ -2865,7 +2880,7 @@ namespace ts {
28652880
return matchedValue;
28662881
}
28672882

2868-
function isPatternMatch({prefix, suffix}: Pattern, candidate: string) {
2883+
function isPatternMatch({ prefix, suffix }: Pattern, candidate: string) {
28692884
return candidate.length >= prefix.length + suffix.length &&
28702885
startsWith(candidate, prefix) &&
28712886
endsWith(candidate, suffix);

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,7 @@ namespace ts {
37093709
while (statementOffset < numStatements) {
37103710
const statement = source[statementOffset];
37113711
if (getEmitFlags(statement) & EmitFlags.CustomPrologue) {
3712-
target.push(visitor ? visitNode(statement, visitor, isStatement) : statement);
3712+
append(target, visitor ? visitNode(statement, visitor, isStatement) : statement);
37133713
}
37143714
else {
37153715
break;

src/compiler/performance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace ts {
1010
namespace ts.performance {
1111
declare const onProfilerEvent: { (markName: string): void; profiler: boolean; };
1212

13-
const profilerEvent: (markName: string) => void = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true ? onProfilerEvent : noop;
13+
// NOTE: cannot use ts.noop as core.ts loads after this
14+
const profilerEvent: (markName: string) => void = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true ? onProfilerEvent : () => { /*empty*/ };
1415

1516
let enabled = false;
1617
let profilerStart = 0;

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ namespace ts {
294294
}
295295

296296
/* @internal */
297-
export function stringToToken(s: string): SyntaxKind {
297+
export function stringToToken(s: string): SyntaxKind | undefined {
298298
return textToToken.get(s);
299299
}
300300

src/compiler/sys.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ namespace ts {
125125
};
126126

127127
export let sys: System = (() => {
128+
const utf8ByteOrderMark = "\u00EF\u00BB\u00BF";
129+
128130
function getNodeSystem(): System {
129131
const _fs = require("fs");
130132
const _path = require("path");
@@ -348,7 +350,7 @@ namespace ts {
348350
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
349351
// If a BOM is required, emit one
350352
if (writeByteOrderMark) {
351-
data = "\uFEFF" + data;
353+
data = utf8ByteOrderMark + data;
352354
}
353355

354356
let fd: number;
@@ -549,7 +551,7 @@ namespace ts {
549551
writeFile(path: string, data: string, writeByteOrderMark?: boolean) {
550552
// If a BOM is required, emit one
551553
if (writeByteOrderMark) {
552-
data = "\uFEFF" + data;
554+
data = utf8ByteOrderMark + data;
553555
}
554556

555557
ChakraHost.writeFile(path, data);

0 commit comments

Comments
 (0)