mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge master
This commit is contained in:
commit
487e2ffe2a
324 files changed
+113384
-84213
No files matched your search
+32
-17
@@ -120,7 +120,7 @@ namespace ts {
|
||||
let thisParentContainer: Node; // Container one level up
|
||||
let blockScopeContainer: Node;
|
||||
let lastContainer: Node;
|
||||
let delayedTypeAliases: (JSDocTypedefTag | JSDocCallbackTag)[];
|
||||
let delayedTypeAliases: (JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag)[];
|
||||
let seenThisKeyword: boolean;
|
||||
|
||||
// state used by control flow analysis
|
||||
@@ -490,11 +490,11 @@ namespace ts {
|
||||
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
|
||||
if (isJSDocTypeAlias(node)) Debug.assert(isInJSFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
|
||||
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypeAlias(node)) {
|
||||
if (hasModifier(node, ModifierFlags.Default) && !getDeclarationName(node)) {
|
||||
if (!container.locals || (hasModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) {
|
||||
return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default!
|
||||
}
|
||||
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
|
||||
const local = declareSymbol(container.locals!, /*parent*/ undefined, node, exportKind, symbolExcludes);
|
||||
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
|
||||
local.exportSymbol = declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes);
|
||||
node.localSymbol = local;
|
||||
return local;
|
||||
@@ -732,7 +732,8 @@ namespace ts {
|
||||
break;
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
case SyntaxKind.JSDocCallbackTag:
|
||||
bindJSDocTypeAlias(node as JSDocTypedefTag | JSDocCallbackTag);
|
||||
case SyntaxKind.JSDocEnumTag:
|
||||
bindJSDocTypeAlias(node as JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag);
|
||||
break;
|
||||
// In source files and blocks, bind functions first to match hoisting that occurs at runtime
|
||||
case SyntaxKind.SourceFile: {
|
||||
@@ -1436,9 +1437,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag) {
|
||||
function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag) {
|
||||
node.tagName.parent = node;
|
||||
if (node.fullName) {
|
||||
if (node.kind !== SyntaxKind.JSDocEnumTag && node.fullName) {
|
||||
setParentPointers(node, node.fullName);
|
||||
}
|
||||
}
|
||||
@@ -1805,7 +1806,19 @@ namespace ts {
|
||||
currentFlow = { flags: FlowFlags.Start };
|
||||
parent = typeAlias;
|
||||
bind(typeAlias.typeExpression);
|
||||
if (!typeAlias.fullName || typeAlias.fullName.kind === SyntaxKind.Identifier) {
|
||||
const declName = getNameOfDeclaration(typeAlias);
|
||||
if ((isJSDocEnumTag(typeAlias) || !typeAlias.fullName) && declName && isPropertyAccessEntityNameExpression(declName.parent)) {
|
||||
// typedef anchored to an A.B.C assignment - we need to bind into B's namespace under name C
|
||||
const isTopLevel = isTopLevelNamespaceAssignment(declName.parent);
|
||||
if (isTopLevel) {
|
||||
bindPotentiallyMissingNamespaces(file.symbol, declName.parent, isTopLevel, !!findAncestor(declName, d => isPropertyAccessExpression(d) && d.name.escapedText === "prototype"));
|
||||
const oldContainer = container;
|
||||
container = isPropertyAccessExpression(declName.parent.expression) ? declName.parent.expression.name : declName.parent.expression;
|
||||
declareModuleMember(typeAlias, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
|
||||
container = oldContainer;
|
||||
}
|
||||
}
|
||||
else if (isJSDocEnumTag(typeAlias) || !typeAlias.fullName || typeAlias.fullName.kind === SyntaxKind.Identifier) {
|
||||
parent = typeAlias.parent;
|
||||
bindBlockScopedDeclaration(typeAlias, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
|
||||
}
|
||||
@@ -2319,7 +2332,8 @@ namespace ts {
|
||||
return declareSymbolAndAddToSymbolTable(propTag, flags, SymbolFlags.PropertyExcludes);
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
case SyntaxKind.JSDocCallbackTag:
|
||||
return (delayedTypeAliases || (delayedTypeAliases = [])).push(node as JSDocTypedefTag | JSDocCallbackTag);
|
||||
case SyntaxKind.JSDocEnumTag:
|
||||
return (delayedTypeAliases || (delayedTypeAliases = [])).push(node as JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2605,7 +2619,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindPotentiallyMissingNamespaces(namespaceSymbol: Symbol | undefined, entityName: EntityNameExpression, isToplevel: boolean, isPrototypeProperty: boolean) {
|
||||
if (isToplevel && !isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace))) {
|
||||
if (isToplevel && !isPrototypeProperty) {
|
||||
// make symbols or add declarations for intermediate containers
|
||||
const flags = SymbolFlags.Module | SymbolFlags.Assignment;
|
||||
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.Assignment;
|
||||
@@ -2640,11 +2654,15 @@ namespace ts {
|
||||
declareSymbol(symbolTable, namespaceSymbol, declaration, includes | SymbolFlags.Assignment, excludes & ~SymbolFlags.Assignment);
|
||||
}
|
||||
|
||||
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
|
||||
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
|
||||
const isToplevel = isBinaryExpression(propertyAccess.parent)
|
||||
function isTopLevelNamespaceAssignment(propertyAccess: PropertyAccessEntityNameExpression) {
|
||||
return isBinaryExpression(propertyAccess.parent)
|
||||
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile
|
||||
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
|
||||
}
|
||||
|
||||
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
|
||||
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
|
||||
const isToplevel = isTopLevelNamespaceAssignment(propertyAccess);
|
||||
namespaceSymbol = bindPotentiallyMissingNamespaces(namespaceSymbol, propertyAccess.expression, isToplevel, isPrototypeProperty);
|
||||
bindPotentiallyNewExpandoMemberToNamespace(propertyAccess, namespaceSymbol, isPrototypeProperty);
|
||||
}
|
||||
@@ -2766,11 +2784,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (!isBindingPattern(node.name)) {
|
||||
const isEnum = isInJSFile(node) && !!getJSDocEnumTag(node);
|
||||
const enumFlags = (isEnum ? SymbolFlags.RegularEnum : SymbolFlags.None);
|
||||
const enumExcludes = (isEnum ? SymbolFlags.RegularEnumExcludes : SymbolFlags.None);
|
||||
if (isBlockOrCatchScoped(node)) {
|
||||
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable | enumFlags, SymbolFlags.BlockScopedVariableExcludes | enumExcludes);
|
||||
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
||||
}
|
||||
else if (isParameterDeclaration(node)) {
|
||||
// It is safe to walk up parent chain to find whether the node is a destructuring parameter declaration
|
||||
@@ -2785,7 +2800,7 @@ namespace ts {
|
||||
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes);
|
||||
}
|
||||
else {
|
||||
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable | enumFlags, SymbolFlags.FunctionScopedVariableExcludes | enumExcludes);
|
||||
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+550
-431
File diff suppressed because it is too large.
Load diff
@@ -1743,6 +1743,16 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export interface TSConfig {
|
||||
compilerOptions: CompilerOptions;
|
||||
compileOnSave: boolean | undefined;
|
||||
exclude?: ReadonlyArray<string>;
|
||||
files: ReadonlyArray<string> | undefined;
|
||||
include?: ReadonlyArray<string>;
|
||||
references: ReadonlyArray<ProjectReference> | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an uncommented, complete tsconfig for use with "--showConfig"
|
||||
* @param configParseResult options to be generated into tsconfig.json
|
||||
@@ -1750,7 +1760,7 @@ namespace ts {
|
||||
* @param host provides current directory and case sensitivity services
|
||||
*/
|
||||
/** @internal */
|
||||
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): object {
|
||||
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): TSConfig {
|
||||
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
|
||||
const files = map(
|
||||
filter(
|
||||
@@ -1778,13 +1788,13 @@ namespace ts {
|
||||
build: undefined,
|
||||
version: undefined,
|
||||
},
|
||||
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath, originalPath: undefined })),
|
||||
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath ? r.originalPath : "", originalPath: undefined })),
|
||||
files: length(files) ? files : undefined,
|
||||
...(configParseResult.configFileSpecs ? {
|
||||
include: filterSameAsDefaultInclude(configParseResult.configFileSpecs.validatedIncludeSpecs),
|
||||
exclude: configParseResult.configFileSpecs.validatedExcludeSpecs
|
||||
} : {}),
|
||||
compilerOnSave: !!configParseResult.compileOnSave ? true : undefined
|
||||
compileOnSave: !!configParseResult.compileOnSave ? true : undefined
|
||||
};
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1381,6 +1381,17 @@ namespace ts {
|
||||
return keys;
|
||||
}
|
||||
|
||||
export function getAllKeys(obj: object): string[] {
|
||||
const result: string[] = [];
|
||||
do {
|
||||
const names = Object.getOwnPropertyNames(obj);
|
||||
for (const name of names) {
|
||||
pushIfUnique(result, name);
|
||||
}
|
||||
} while (obj = Object.getPrototypeOf(obj));
|
||||
return result;
|
||||
}
|
||||
|
||||
export function getOwnValues<T>(sparseArray: T[]): T[] {
|
||||
const values: T[] = [];
|
||||
for (const key in sparseArray) {
|
||||
|
||||
@@ -258,4 +258,4 @@ namespace ts {
|
||||
isDebugInfoEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3636,15 +3636,16 @@ namespace ts {
|
||||
name: "typescript:values",
|
||||
scoped: false,
|
||||
text: `
|
||||
var __values = (this && this.__values) || function (o) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
||||
var __values = (this && this.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
return {
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};`
|
||||
};
|
||||
|
||||
|
||||
+17
-2
@@ -605,6 +605,8 @@ namespace ts {
|
||||
|
||||
let parsingContext: ParsingContext;
|
||||
|
||||
let notParenthesizedArrow: Map<true> | undefined;
|
||||
|
||||
// Flags that dictate what parsing context we're in. For example:
|
||||
// Whether or not we are in strict parsing mode. All that changes in strict parsing mode is
|
||||
// that some tokens that would be considered identifiers may be considered keywords.
|
||||
@@ -826,6 +828,7 @@ namespace ts {
|
||||
identifiers = undefined!;
|
||||
syntaxCursor = undefined;
|
||||
sourceText = undefined!;
|
||||
notParenthesizedArrow = undefined!;
|
||||
}
|
||||
|
||||
function parseSourceFileWorker(fileName: string, languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind): SourceFile {
|
||||
@@ -2431,10 +2434,12 @@ namespace ts {
|
||||
const moduleSpecifier = parseOptionalToken(SyntaxKind.ModuleKeyword);
|
||||
if (moduleSpecifier) {
|
||||
const moduleTag = createNode(SyntaxKind.JSDocNamepathType, moduleSpecifier.pos) as JSDocNamepathType;
|
||||
const terminators = [SyntaxKind.CloseBraceToken, SyntaxKind.EndOfFileToken, SyntaxKind.CommaToken, SyntaxKind.CloseParenToken];
|
||||
const terminators = [SyntaxKind.CloseBraceToken, SyntaxKind.EndOfFileToken, SyntaxKind.CommaToken, SyntaxKind.CloseParenToken, SyntaxKind.WhitespaceTrivia];
|
||||
while (terminators.indexOf(token()) < 0) {
|
||||
nextTokenJSDoc();
|
||||
}
|
||||
|
||||
scanner.setInJSDocType(false);
|
||||
return finishNode(moduleTag);
|
||||
}
|
||||
|
||||
@@ -3686,7 +3691,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction | undefined {
|
||||
return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
|
||||
const tokenPos = scanner.getTokenPos();
|
||||
if (notParenthesizedArrow && notParenthesizedArrow.has(tokenPos.toString())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const result = parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
|
||||
if (!result) {
|
||||
(notParenthesizedArrow || (notParenthesizedArrow = createMap())).set(tokenPos.toString(), true);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction | undefined {
|
||||
|
||||
@@ -762,7 +762,7 @@ namespace ts {
|
||||
let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference) => ResolvedModuleFull[];
|
||||
const hasInvalidatedResolution = host.hasInvalidatedResolution || returnFalse;
|
||||
if (host.resolveModuleNames) {
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile, reusedNames, redirectedReference) => host.resolveModuleNames!(Debug.assertEachDefined(moduleNames), containingFile, reusedNames, redirectedReference).map(resolved => {
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile, reusedNames, redirectedReference) => host.resolveModuleNames!(Debug.assertEachDefined(moduleNames), containingFile, reusedNames, redirectedReference, options).map(resolved => {
|
||||
// An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName.
|
||||
if (!resolved || (resolved as ResolvedModuleFull).extension !== undefined) {
|
||||
return resolved as ResolvedModuleFull;
|
||||
@@ -780,7 +780,7 @@ namespace ts {
|
||||
|
||||
let resolveTypeReferenceDirectiveNamesWorker: (typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference) => (ResolvedTypeReferenceDirective | undefined)[];
|
||||
if (host.resolveTypeReferenceDirectives) {
|
||||
resolveTypeReferenceDirectiveNamesWorker = (typeDirectiveNames, containingFile, redirectedReference) => host.resolveTypeReferenceDirectives!(Debug.assertEachDefined(typeDirectiveNames), containingFile, redirectedReference);
|
||||
resolveTypeReferenceDirectiveNamesWorker = (typeDirectiveNames, containingFile, redirectedReference) => host.resolveTypeReferenceDirectives!(Debug.assertEachDefined(typeDirectiveNames), containingFile, redirectedReference, options);
|
||||
}
|
||||
else {
|
||||
const loader = (typesRef: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference).resolvedTypeReferenceDirective!; // TODO: GH#18217
|
||||
@@ -814,7 +814,10 @@ namespace ts {
|
||||
let mapFromFileToProjectReferenceRedirects: Map<Path> | undefined;
|
||||
|
||||
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
|
||||
const structuralIsReused = tryReuseStructureFromOldProgram();
|
||||
// We set `structuralIsReused` to `undefined` because `tryReuseStructureFromOldProgram` calls `tryReuseStructureFromOldProgram` which checks
|
||||
// `structuralIsReused`, which would be a TDZ violation if it was not set in advance to `undefined`.
|
||||
let structuralIsReused: StructureIsReused | undefined;
|
||||
structuralIsReused = tryReuseStructureFromOldProgram();
|
||||
if (structuralIsReused !== StructureIsReused.Completely) {
|
||||
processingDefaultLibFiles = [];
|
||||
processingOtherFiles = [];
|
||||
|
||||
+57
-16
@@ -248,6 +248,15 @@ namespace ts {
|
||||
const unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ];
|
||||
const unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285,Line truncated
|
||||
|
||||
/**
|
||||
* Generated by scripts/regenerate-unicode-identifier-parts.js on node v12.4.0 with unicode 12.1
|
||||
* based on http://www.unicode.org/reports/tr31/ and https://www.ecma-international.org/ecma-262/6.0/#sec-names-and-keywords
|
||||
* unicodeESNextIdentifierStart corresponds to the ID_Start and Other_ID_Start property, and
|
||||
* unicodeESNextIdentifierPart corresponds to ID_Continue, Other_ID_Continue, plus ID_Start and Other_ID_Start
|
||||
*/
|
||||
const unicodeESNextIdentifierStart = [65, 90, 97, 122, 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 895, 895, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1327, 1329, 1366, 1369, 1369, 1376, 1416, 1488, 1514, 1519, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2144, 2154, 2208, 2228, 2230, 2237, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2432, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2556, 2556, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2809, 2809, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3129, 3133, 3133, 3160, 3162, 3168, 3169, 3200, 3200, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3412, 3414, 3423, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3718, 3722, 3724, 3747, 3749, 3749, 3751, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5109, 5112, 5117, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5880, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6264, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6430, 6480, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7296, 7304, 7312, 7354, 7357, 7359, 7401, 7404, 7406, 7411, 7413, 7414, 7418, 7418, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8472, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12443, 12447, 12449, 12538, 12540, 12543, 12549, 12591, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40943, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42653, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42943, 42946, 42950, 42999, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43261, 43262, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43488, 43492, 43494, 43503, 43514, 43518, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43646, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43824, 43866, 43868, 43879, 43888, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65536, 65547, 65549, 65574, 65576, 65594, 65596, 65597, 65599, 65613, 65616, 65629, 65664, 65786, 65856, 65908, 66176, 66204, 66208, 66256, 66304, 66335, 66349, 66378, 66384, 66421, 66432, 66461, 66464, 66499, 66504, 66511, 66513, 66517, 665Line truncated
|
||||
const unicodeESNextIdentifierPart = [48, 57, 65, 90, 95, 95, 97, 122, 170, 170, 181, 181, 183, 183, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 895, 895, 902, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1327, 1329, 1366, 1369, 1369, 1376, 1416, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1519, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2045, 2045, 2048, 2093, 2112, 2139, 2144, 2154, 2208, 2228, 2230, 2237, 2259, 2273, 2275, 2403, 2406, 2415, 2417, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2556, 2556, 2558, 2558, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2809, 2815, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3072, 3084, 3086, 3088, 3090, 3112, 3114, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3162, 3168, 3171, 3174, 3183, 3200, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3328, 3331, 3333, 3340, 3342, 3344, 3346, 3396, 3398, 3400, 3402, 3406, 3412, 3415, 3423, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3558, 3567, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3718, 3722, 3724, 3747, 3749, 3749, 3751, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4969, 4977, 4992, 5007, 5024, 5109, 5112, 5117, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5880, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6264, 6272, 6314, 6320, 6389, 6400, 6430, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6618, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6832, 6845, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7296, 7304, 7312, 7354, 7357, 7359, 7376, 7378, 7380, 7418, 7424, 7673, 7675, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8472, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12447, 12449, 12538, 12540, 12543, 12549, 12591, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40943, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42737, 42775, 42783, 42786, 42888, 42891, 42943, 42946, 42950, 42999, 43047, 43072, 43123, 43136, 43205, 43216, 43225, 43232, 43255, 43259, 43259, 43261, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43488, 43518, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43824, 43866, 43868, 43879, 43888, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296Line truncated
|
||||
|
||||
function lookupInUnicodeMap(code: number, map: ReadonlyArray<number>): boolean {
|
||||
// Bail out quickly if it couldn't possibly be in the map.
|
||||
if (code < map[0]) {
|
||||
@@ -279,14 +288,16 @@ namespace ts {
|
||||
}
|
||||
|
||||
/* @internal */ export function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget | undefined) {
|
||||
return languageVersion! >= ScriptTarget.ES5 ?
|
||||
lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
|
||||
return languageVersion! >= ScriptTarget.ES2015 ?
|
||||
lookupInUnicodeMap(code, unicodeESNextIdentifierStart) :
|
||||
languageVersion! === ScriptTarget.ES5 ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
|
||||
lookupInUnicodeMap(code, unicodeES3IdentifierStart);
|
||||
}
|
||||
|
||||
function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget | undefined) {
|
||||
return languageVersion! >= ScriptTarget.ES5 ?
|
||||
lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
|
||||
return languageVersion! >= ScriptTarget.ES2015 ?
|
||||
lookupInUnicodeMap(code, unicodeESNextIdentifierPart) :
|
||||
languageVersion! === ScriptTarget.ES5 ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
|
||||
lookupInUnicodeMap(code, unicodeES3IdentifierPart);
|
||||
}
|
||||
|
||||
@@ -821,12 +832,13 @@ namespace ts {
|
||||
|
||||
/* @internal */
|
||||
export function isIdentifierText(name: string, languageVersion: ScriptTarget | undefined): boolean {
|
||||
if (!isIdentifierStart(name.charCodeAt(0), languageVersion)) {
|
||||
let ch = codePointAt(name, 0);
|
||||
if (!isIdentifierStart(ch, languageVersion)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 1; i < name.length; i++) {
|
||||
if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) {
|
||||
for (let i = charSize(ch); i < name.length; i += charSize(ch)) {
|
||||
if (!isIdentifierPart(ch = codePointAt(name, i), languageVersion)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1334,9 +1346,9 @@ namespace ts {
|
||||
let result = "";
|
||||
let start = pos;
|
||||
while (pos < end) {
|
||||
let ch = text.charCodeAt(pos);
|
||||
let ch = codePointAt(text, pos);
|
||||
if (isIdentifierPart(ch, languageVersion)) {
|
||||
pos++;
|
||||
pos += charSize(ch);
|
||||
}
|
||||
else if (ch === CharacterCodes.backslash) {
|
||||
ch = peekUnicodeEscape();
|
||||
@@ -1344,7 +1356,7 @@ namespace ts {
|
||||
break;
|
||||
}
|
||||
result += text.substring(start, pos);
|
||||
result += String.fromCharCode(ch);
|
||||
result += utf16EncodeAsString(ch);
|
||||
// Valid Unicode escape is always six characters
|
||||
pos += 6;
|
||||
start = pos;
|
||||
@@ -1442,7 +1454,7 @@ namespace ts {
|
||||
if (pos >= end) {
|
||||
return token = SyntaxKind.EndOfFileToken;
|
||||
}
|
||||
let ch = text.charCodeAt(pos);
|
||||
let ch = codePointAt(text, pos);
|
||||
|
||||
// Special handling for shebang
|
||||
if (ch === CharacterCodes.hash && pos === 0 && isShebangTrivia(text, pos)) {
|
||||
@@ -1835,8 +1847,8 @@ namespace ts {
|
||||
return token = SyntaxKind.Unknown;
|
||||
default:
|
||||
if (isIdentifierStart(ch, languageVersion)) {
|
||||
pos++;
|
||||
while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++;
|
||||
pos += charSize(ch);
|
||||
while (pos < end && isIdentifierPart(ch = codePointAt(text, pos), languageVersion)) pos += charSize(ch);
|
||||
tokenValue = text.substring(tokenPos, pos);
|
||||
if (ch === CharacterCodes.backslash) {
|
||||
tokenValue += scanIdentifierParts();
|
||||
@@ -1844,16 +1856,16 @@ namespace ts {
|
||||
return token = getIdentifierToken();
|
||||
}
|
||||
else if (isWhiteSpaceSingleLine(ch)) {
|
||||
pos++;
|
||||
pos += charSize(ch);
|
||||
continue;
|
||||
}
|
||||
else if (isLineBreak(ch)) {
|
||||
tokenFlags |= TokenFlags.PrecedingLineBreak;
|
||||
pos++;
|
||||
pos += charSize(ch);
|
||||
continue;
|
||||
}
|
||||
error(Diagnostics.Invalid_character);
|
||||
pos++;
|
||||
pos += charSize(ch);
|
||||
return token = SyntaxKind.Unknown;
|
||||
}
|
||||
}
|
||||
@@ -2199,4 +2211,33 @@ namespace ts {
|
||||
inJSDocType += inType ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
const codePointAt: (s: string, i: number) => number = (String.prototype as any).codePointAt ? (s, i) => (s as any).codePointAt(i) : function codePointAt(str, i): number {
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt
|
||||
const size = str.length;
|
||||
// Account for out-of-bounds indices:
|
||||
if (i < 0 || i >= size) {
|
||||
return undefined!; // String.codePointAt returns `undefined` for OOB indexes
|
||||
}
|
||||
// Get the first code unit
|
||||
const first = str.charCodeAt(i);
|
||||
// check if it’s the start of a surrogate pair
|
||||
if (first >= 0xD800 && first <= 0xDBFF && size > i + 1) { // high surrogate and there is a next code unit
|
||||
const second = str.charCodeAt(i + 1);
|
||||
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
|
||||
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
};
|
||||
|
||||
/* @internal */
|
||||
function charSize(ch: number) {
|
||||
if (ch > 0x10000) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+118
-48
@@ -304,6 +304,53 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function createSingleFileWatcherPerName(
|
||||
watchFile: HostWatchFile,
|
||||
useCaseSensitiveFileNames: boolean
|
||||
): HostWatchFile {
|
||||
interface SingleFileWatcher {
|
||||
watcher: FileWatcher;
|
||||
refCount: number;
|
||||
}
|
||||
const cache = createMap<SingleFileWatcher>();
|
||||
const callbacksCache = createMultiMap<FileWatcherCallback>();
|
||||
const toCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
|
||||
|
||||
return (fileName, callback, pollingInterval) => {
|
||||
const path = toCanonicalFileName(fileName);
|
||||
const existing = cache.get(path);
|
||||
if (existing) {
|
||||
existing.refCount++;
|
||||
}
|
||||
else {
|
||||
cache.set(path, {
|
||||
watcher: watchFile(
|
||||
fileName,
|
||||
(fileName, eventKind) => forEach(
|
||||
callbacksCache.get(path),
|
||||
cb => cb(fileName, eventKind)
|
||||
),
|
||||
pollingInterval
|
||||
),
|
||||
refCount: 1
|
||||
});
|
||||
}
|
||||
callbacksCache.add(path, callback);
|
||||
|
||||
return {
|
||||
close: () => {
|
||||
const watcher = Debug.assertDefined(cache.get(path));
|
||||
callbacksCache.remove(path, callback);
|
||||
watcher.refCount--;
|
||||
if (watcher.refCount) return;
|
||||
cache.delete(path);
|
||||
closeFileWatcherOf(watcher);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if file status changed
|
||||
*/
|
||||
@@ -472,59 +519,81 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
|
||||
|
||||
/*@internal*/
|
||||
interface NodeBuffer extends Uint8Array {
|
||||
write(str: string, offset?: number, length?: number, encoding?: string): number;
|
||||
constructor: any;
|
||||
write(str: string, encoding?: BufferEncoding): number;
|
||||
write(str: string, offset: number, encoding?: BufferEncoding): number;
|
||||
write(str: string, offset: number, length: number, encoding?: BufferEncoding): number;
|
||||
toString(encoding?: string, start?: number, end?: number): string;
|
||||
toJSON(): { type: "Buffer", data: any[] };
|
||||
equals(otherBuffer: Buffer): boolean;
|
||||
compare(otherBuffer: Buffer, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;
|
||||
copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
|
||||
slice(start?: number, end?: number): Buffer;
|
||||
writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
|
||||
readUInt8(offset: number, noAssert?: boolean): number;
|
||||
readUInt16LE(offset: number, noAssert?: boolean): number;
|
||||
readUInt16BE(offset: number, noAssert?: boolean): number;
|
||||
readUInt32LE(offset: number, noAssert?: boolean): number;
|
||||
readUInt32BE(offset: number, noAssert?: boolean): number;
|
||||
readInt8(offset: number, noAssert?: boolean): number;
|
||||
readInt16LE(offset: number, noAssert?: boolean): number;
|
||||
readInt16BE(offset: number, noAssert?: boolean): number;
|
||||
readInt32LE(offset: number, noAssert?: boolean): number;
|
||||
readInt32BE(offset: number, noAssert?: boolean): number;
|
||||
readFloatLE(offset: number, noAssert?: boolean): number;
|
||||
readFloatBE(offset: number, noAssert?: boolean): number;
|
||||
readDoubleLE(offset: number, noAssert?: boolean): number;
|
||||
readDoubleBE(offset: number, noAssert?: boolean): number;
|
||||
toJSON(): { type: "Buffer"; data: number[] };
|
||||
equals(otherBuffer: Uint8Array): boolean;
|
||||
compare(
|
||||
otherBuffer: Uint8Array,
|
||||
targetStart?: number,
|
||||
targetEnd?: number,
|
||||
sourceStart?: number,
|
||||
sourceEnd?: number
|
||||
): number;
|
||||
copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
|
||||
slice(begin?: number, end?: number): Buffer;
|
||||
subarray(begin?: number, end?: number): Buffer;
|
||||
writeUIntLE(value: number, offset: number, byteLength: number): number;
|
||||
writeUIntBE(value: number, offset: number, byteLength: number): number;
|
||||
writeIntLE(value: number, offset: number, byteLength: number): number;
|
||||
writeIntBE(value: number, offset: number, byteLength: number): number;
|
||||
readUIntLE(offset: number, byteLength: number): number;
|
||||
readUIntBE(offset: number, byteLength: number): number;
|
||||
readIntLE(offset: number, byteLength: number): number;
|
||||
readIntBE(offset: number, byteLength: number): number;
|
||||
readUInt8(offset: number): number;
|
||||
readUInt16LE(offset: number): number;
|
||||
readUInt16BE(offset: number): number;
|
||||
readUInt32LE(offset: number): number;
|
||||
readUInt32BE(offset: number): number;
|
||||
readInt8(offset: number): number;
|
||||
readInt16LE(offset: number): number;
|
||||
readInt16BE(offset: number): number;
|
||||
readInt32LE(offset: number): number;
|
||||
readInt32BE(offset: number): number;
|
||||
readFloatLE(offset: number): number;
|
||||
readFloatBE(offset: number): number;
|
||||
readDoubleLE(offset: number): number;
|
||||
readDoubleBE(offset: number): number;
|
||||
reverse(): this;
|
||||
swap16(): Buffer;
|
||||
swap32(): Buffer;
|
||||
swap64(): Buffer;
|
||||
writeUInt8(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeUInt16LE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeUInt16BE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeUInt32LE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeUInt32BE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeInt8(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeInt16LE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeInt16BE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeInt32LE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeInt32BE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeFloatLE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeFloatBE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;
|
||||
writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;
|
||||
fill(value: any, offset?: number, end?: number): this;
|
||||
indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
|
||||
lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
|
||||
writeUInt8(value: number, offset: number): number;
|
||||
writeUInt16LE(value: number, offset: number): number;
|
||||
writeUInt16BE(value: number, offset: number): number;
|
||||
writeUInt32LE(value: number, offset: number): number;
|
||||
writeUInt32BE(value: number, offset: number): number;
|
||||
writeInt8(value: number, offset: number): number;
|
||||
writeInt16LE(value: number, offset: number): number;
|
||||
writeInt16BE(value: number, offset: number): number;
|
||||
writeInt32LE(value: number, offset: number): number;
|
||||
writeInt32BE(value: number, offset: number): number;
|
||||
writeFloatLE(value: number, offset: number): number;
|
||||
writeFloatBE(value: number, offset: number): number;
|
||||
writeDoubleLE(value: number, offset: number): number;
|
||||
writeDoubleBE(value: number, offset: number): number;
|
||||
readBigUInt64BE(offset?: number): bigint;
|
||||
readBigUInt64LE(offset?: number): bigint;
|
||||
readBigInt64BE(offset?: number): bigint;
|
||||
readBigInt64LE(offset?: number): bigint;
|
||||
writeBigInt64BE(value: bigint, offset?: number): number;
|
||||
writeBigInt64LE(value: bigint, offset?: number): number;
|
||||
writeBigUInt64BE(value: bigint, offset?: number): number;
|
||||
writeBigUInt64LE(value: bigint, offset?: number): number;
|
||||
fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
|
||||
indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
||||
lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean;
|
||||
includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
|
||||
keys(): IterableIterator<number>;
|
||||
values(): IterableIterator<number>;
|
||||
}
|
||||
@@ -673,6 +742,7 @@ namespace ts {
|
||||
const useNonPollingWatchers = process.env.TSC_NONPOLLING_WATCHER;
|
||||
const tscWatchFile = process.env.TSC_WATCHFILE;
|
||||
const tscWatchDirectory = process.env.TSC_WATCHDIRECTORY;
|
||||
const fsWatchFile = createSingleFileWatcherPerName(fsWatchFileWorker, useCaseSensitiveFileNames);
|
||||
let dynamicPollingWatchFile: HostWatchFile | undefined;
|
||||
const nodeSystem: System = {
|
||||
args: process.argv.slice(2),
|
||||
@@ -813,7 +883,7 @@ namespace ts {
|
||||
return useNonPollingWatchers ?
|
||||
createNonPollingWatchFile() :
|
||||
// Default to do not use polling interval as it is before this experiment branch
|
||||
(fileName, callback) => fsWatchFile(fileName, callback);
|
||||
(fileName, callback) => fsWatchFile(fileName, callback, /*pollingInterval*/ undefined);
|
||||
}
|
||||
|
||||
function getWatchDirectory(): HostWatchDirectory {
|
||||
@@ -894,7 +964,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function fsWatchFile(fileName: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher {
|
||||
function fsWatchFileWorker(fileName: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher {
|
||||
_fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged);
|
||||
let eventKind: FileWatcherEventKind;
|
||||
return {
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace ts {
|
||||
let currentSourceFile: SourceFile;
|
||||
let refs: Map<SourceFile>;
|
||||
let libs: Map<boolean>;
|
||||
let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass
|
||||
const resolver = context.getEmitResolver();
|
||||
const options = context.getCompilerOptions();
|
||||
const newLine = getNewLineCharacter(options);
|
||||
@@ -279,7 +280,7 @@ namespace ts {
|
||||
const statements = visitNodes(node.statements, visitDeclarationStatements);
|
||||
let combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements);
|
||||
refs.forEach(referenceVisitor);
|
||||
const emittedImports = filter(combinedStatements, isAnyImportSyntax);
|
||||
emittedImports = filter(combinedStatements, isAnyImportSyntax);
|
||||
if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) {
|
||||
combinedStatements = setTextRange(createNodeArray([...combinedStatements, createEmptyExports()]), combinedStatements);
|
||||
}
|
||||
@@ -736,6 +737,12 @@ namespace ts {
|
||||
}
|
||||
const oldDiag = getSymbolAccessibilityDiagnostic;
|
||||
|
||||
// Setup diagnostic-related flags before first potential `cleanup` call, otherwise
|
||||
// We'd see a TDZ violation at runtime
|
||||
const canProduceDiagnostic = canProduceDiagnostics(input);
|
||||
const oldWithinObjectLiteralType = suppressNewDiagnosticContexts;
|
||||
let shouldEnterSuppressNewDiagnosticsContextContext = ((input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration);
|
||||
|
||||
// Emit methods which are private as properties with no type information
|
||||
if (isMethodDeclaration(input) || isMethodSignature(input)) {
|
||||
if (hasModifier(input, ModifierFlags.Private)) {
|
||||
@@ -744,8 +751,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const canProdiceDiagnostic = canProduceDiagnostics(input);
|
||||
if (canProdiceDiagnostic && !suppressNewDiagnosticContexts) {
|
||||
if (canProduceDiagnostic && !suppressNewDiagnosticContexts) {
|
||||
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input as DeclarationDiagnosticProducing);
|
||||
}
|
||||
|
||||
@@ -753,8 +759,6 @@ namespace ts {
|
||||
checkEntityNameVisibility(input.exprName, enclosingDeclaration);
|
||||
}
|
||||
|
||||
const oldWithinObjectLiteralType = suppressNewDiagnosticContexts;
|
||||
let shouldEnterSuppressNewDiagnosticsContextContext = ((input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration);
|
||||
if (shouldEnterSuppressNewDiagnosticsContextContext) {
|
||||
// We stop making new diagnostic contexts within object literal types. Unless it's an object type on the RHS of a type alias declaration. Then we do.
|
||||
suppressNewDiagnosticContexts = true;
|
||||
@@ -909,13 +913,13 @@ namespace ts {
|
||||
return cleanup(visitEachChild(input, visitDeclarationSubtree, context));
|
||||
|
||||
function cleanup<T extends Node>(returnValue: T | undefined): T | undefined {
|
||||
if (returnValue && canProdiceDiagnostic && hasDynamicName(input as Declaration)) {
|
||||
if (returnValue && canProduceDiagnostic && hasDynamicName(input as Declaration)) {
|
||||
checkName(input as DeclarationDiagnosticProducing);
|
||||
}
|
||||
if (isEnclosingDeclaration(input)) {
|
||||
enclosingDeclaration = previousEnclosingDeclaration;
|
||||
}
|
||||
if (canProdiceDiagnostic && !suppressNewDiagnosticContexts) {
|
||||
if (canProduceDiagnostic && !suppressNewDiagnosticContexts) {
|
||||
getSymbolAccessibilityDiagnostic = oldDiag;
|
||||
}
|
||||
if (shouldEnterSuppressNewDiagnosticsContextContext) {
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace ts {
|
||||
const previousOnSubstituteNode = context.onSubstituteNode;
|
||||
context.onSubstituteNode = onSubstituteNode;
|
||||
|
||||
let exportedVariableStatement = false;
|
||||
let enabledSubstitutions: ESNextSubstitutionFlags;
|
||||
let enclosingFunctionFlags: FunctionFlags;
|
||||
let enclosingSuperContainerFlags: NodeCheckFlags = 0;
|
||||
@@ -40,6 +41,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
exportedVariableStatement = false;
|
||||
const visited = visitEachChild(node, visitor, context);
|
||||
addEmitHelpers(visited, context.readEmitHelpers());
|
||||
return visited;
|
||||
@@ -79,6 +81,8 @@ namespace ts {
|
||||
return visitBinaryExpression(node as BinaryExpression, noDestructuringValue);
|
||||
case SyntaxKind.CatchClause:
|
||||
return visitCatchClause(node as CatchClause);
|
||||
case SyntaxKind.VariableStatement:
|
||||
return visitVariableStatement(node as VariableStatement);
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return visitVariableDeclaration(node as VariableDeclaration);
|
||||
case SyntaxKind.ForOfStatement:
|
||||
@@ -321,19 +325,43 @@ namespace ts {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
function visitVariableStatement(node: VariableStatement): VisitResult<VariableStatement> {
|
||||
if (hasModifier(node, ModifierFlags.Export)) {
|
||||
const savedExportedVariableStatement = exportedVariableStatement;
|
||||
exportedVariableStatement = true;
|
||||
const visited = visitEachChild(node, visitor, context);
|
||||
exportedVariableStatement = savedExportedVariableStatement;
|
||||
return visited;
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a VariableDeclaration node with a binding pattern.
|
||||
*
|
||||
* @param node A VariableDeclaration node.
|
||||
*/
|
||||
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
|
||||
if (exportedVariableStatement) {
|
||||
const savedExportedVariableStatement = exportedVariableStatement;
|
||||
exportedVariableStatement = false;
|
||||
const visited = visitVariableDeclarationWorker(node, /*exportedVariableStatement*/ true);
|
||||
exportedVariableStatement = savedExportedVariableStatement;
|
||||
return visited;
|
||||
}
|
||||
return visitVariableDeclarationWorker(node, /*exportedVariableStatement*/ false);
|
||||
}
|
||||
|
||||
function visitVariableDeclarationWorker(node: VariableDeclaration, exportedVariableStatement: boolean): VisitResult<VariableDeclaration> {
|
||||
// If we are here it is because the name contains a binding pattern with a rest somewhere in it.
|
||||
if (isBindingPattern(node.name) && node.name.transformFlags & TransformFlags.ContainsObjectRestOrSpread) {
|
||||
return flattenDestructuringBinding(
|
||||
node,
|
||||
visitor,
|
||||
context,
|
||||
FlattenLevel.ObjectRest
|
||||
FlattenLevel.ObjectRest,
|
||||
/*rval*/ undefined,
|
||||
exportedVariableStatement
|
||||
);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
|
||||
+45
-2
@@ -564,8 +564,51 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getBuildOrder(state: SolutionBuilderState) {
|
||||
return state.buildOrder ||
|
||||
(state.buildOrder = createBuildOrder(state, state.rootNames.map(f => resolveProjectName(state, f))));
|
||||
return state.buildOrder || createStateBuildOrder(state);
|
||||
}
|
||||
|
||||
function createStateBuildOrder(state: SolutionBuilderState) {
|
||||
const buildOrder = createBuildOrder(state, state.rootNames.map(f => resolveProjectName(state, f)));
|
||||
if (arrayIsEqualTo(state.buildOrder, buildOrder)) return state.buildOrder!;
|
||||
|
||||
// Clear all to ResolvedConfigFilePaths cache to start fresh
|
||||
state.resolvedConfigFilePaths.clear();
|
||||
const currentProjects = arrayToSet(
|
||||
buildOrder,
|
||||
resolved => toResolvedConfigFilePath(state, resolved)
|
||||
) as ConfigFileMap<true>;
|
||||
|
||||
const noopOnDelete = { onDeleteValue: noop };
|
||||
// Config file cache
|
||||
mutateMapSkippingNewValues(state.configFileCache, currentProjects, noopOnDelete);
|
||||
mutateMapSkippingNewValues(state.projectStatus, currentProjects, noopOnDelete);
|
||||
mutateMapSkippingNewValues(state.buildInfoChecked, currentProjects, noopOnDelete);
|
||||
mutateMapSkippingNewValues(state.builderPrograms, currentProjects, noopOnDelete);
|
||||
mutateMapSkippingNewValues(state.diagnostics, currentProjects, noopOnDelete);
|
||||
mutateMapSkippingNewValues(state.projectPendingBuild, currentProjects, noopOnDelete);
|
||||
mutateMapSkippingNewValues(state.projectErrorsReported, currentProjects, noopOnDelete);
|
||||
|
||||
// Remove watches for the program no longer in the solution
|
||||
if (state.watch) {
|
||||
mutateMapSkippingNewValues(
|
||||
state.allWatchedConfigFiles,
|
||||
currentProjects,
|
||||
{ onDeleteValue: closeFileWatcher }
|
||||
);
|
||||
|
||||
mutateMapSkippingNewValues(
|
||||
state.allWatchedWildcardDirectories,
|
||||
currentProjects,
|
||||
{ onDeleteValue: existingMap => existingMap.forEach(closeFileWatcherOf) }
|
||||
);
|
||||
|
||||
mutateMapSkippingNewValues(
|
||||
state.allWatchedInputFiles,
|
||||
currentProjects,
|
||||
{ onDeleteValue: existingMap => existingMap.forEach(closeFileWatcher) }
|
||||
);
|
||||
}
|
||||
return state.buildOrder = buildOrder;
|
||||
}
|
||||
|
||||
function getBuildOrderFor(state: SolutionBuilderState, project: string | undefined, onlyReferences: boolean | undefined) {
|
||||
|
||||
@@ -2473,7 +2473,8 @@ namespace ts {
|
||||
kind: SyntaxKind.JSDocClassTag;
|
||||
}
|
||||
|
||||
export interface JSDocEnumTag extends JSDocTag {
|
||||
export interface JSDocEnumTag extends JSDocTag, Declaration {
|
||||
parent: JSDoc;
|
||||
kind: SyntaxKind.JSDocEnumTag;
|
||||
typeExpression?: JSDocTypeExpression;
|
||||
}
|
||||
@@ -3667,8 +3668,8 @@ namespace ts {
|
||||
|
||||
Enum = RegularEnum | ConstEnum,
|
||||
Variable = FunctionScopedVariable | BlockScopedVariable,
|
||||
Value = Variable | Property | EnumMember | ObjectLiteral | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | Assignment,
|
||||
Type = Class | Interface | Enum | EnumMember | TypeLiteral | TypeParameter | TypeAlias | Assignment,
|
||||
Value = Variable | Property | EnumMember | ObjectLiteral | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
|
||||
Type = Class | Interface | Enum | EnumMember | TypeLiteral | TypeParameter | TypeAlias,
|
||||
Namespace = ValueModule | NamespaceModule | Enum,
|
||||
Module = ValueModule | NamespaceModule,
|
||||
Accessor = GetAccessor | SetAccessor,
|
||||
@@ -3689,7 +3690,7 @@ namespace ts {
|
||||
InterfaceExcludes = Type & ~(Interface | Class),
|
||||
RegularEnumExcludes = (Value | Type) & ~(RegularEnum | ValueModule), // regular enums merge only with regular enums and modules
|
||||
ConstEnumExcludes = (Value | Type) & ~ConstEnum, // const enums merge only with const enums
|
||||
ValueModuleExcludes = Value & ~(Function | Class | RegularEnum | ValueModule | Assignment),
|
||||
ValueModuleExcludes = Value & ~(Function | Class | RegularEnum | ValueModule),
|
||||
NamespaceModuleExcludes = 0,
|
||||
MethodExcludes = Value & ~Method,
|
||||
GetAccessorExcludes = Value & ~SetAccessor,
|
||||
@@ -5179,11 +5180,11 @@ namespace ts {
|
||||
* If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just
|
||||
* 'throw new Error("NotImplemented")'
|
||||
*/
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference): (ResolvedModule | undefined)[];
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
|
||||
/**
|
||||
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
|
||||
*/
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
/* @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void;
|
||||
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
|
||||
|
||||
+42
-10
@@ -566,6 +566,8 @@ namespace ts {
|
||||
return emitNode && emitNode.flags || 0;
|
||||
}
|
||||
|
||||
const escapeNoSubstitutionTemplateLiteralText = compose(escapeString, escapeTemplateSubstitution);
|
||||
const escapeNonAsciiNoSubstitutionTemplateLiteralText = compose(escapeNonAsciiString, escapeTemplateSubstitution);
|
||||
export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile, neverAsciiEscape: boolean | undefined) {
|
||||
// If we don't need to downlevel and we can reach the original source text using
|
||||
// the node's parent reference, then simply get the text as it was originally written.
|
||||
@@ -576,7 +578,11 @@ namespace ts {
|
||||
return getSourceTextOfNodeFromSourceFile(sourceFile, node);
|
||||
}
|
||||
|
||||
const escapeText = neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString : escapeNonAsciiString;
|
||||
// If a NoSubstitutionTemplateLiteral appears to have a substitution in it, the original text
|
||||
// had to include a backslash: `not \${a} substitution`.
|
||||
const escapeText = neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ?
|
||||
node.kind === SyntaxKind.NoSubstitutionTemplateLiteral ? escapeNoSubstitutionTemplateLiteralText : escapeString :
|
||||
node.kind === SyntaxKind.NoSubstitutionTemplateLiteral ? escapeNonAsciiNoSubstitutionTemplateLiteralText : escapeNonAsciiString;
|
||||
|
||||
// If we can't reach the original source text, use the canonical form if it's a number,
|
||||
// or a (possibly escaped) quoted form of the original text if it's string-like.
|
||||
@@ -2147,11 +2153,11 @@ namespace ts {
|
||||
return !!name && name.escapedText === "new";
|
||||
}
|
||||
|
||||
export function isJSDocTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag {
|
||||
return node.kind === SyntaxKind.JSDocTypedefTag || node.kind === SyntaxKind.JSDocCallbackTag;
|
||||
export function isJSDocTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag {
|
||||
return node.kind === SyntaxKind.JSDocTypedefTag || node.kind === SyntaxKind.JSDocCallbackTag || node.kind === SyntaxKind.JSDocEnumTag;
|
||||
}
|
||||
|
||||
export function isTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag | TypeAliasDeclaration {
|
||||
export function isTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag | TypeAliasDeclaration {
|
||||
return isJSDocTypeAlias(node) || isTypeAliasDeclaration(node);
|
||||
}
|
||||
|
||||
@@ -3113,6 +3119,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const templateSubstitutionRegExp = /\$\{/g;
|
||||
function escapeTemplateSubstitution(str: string): string {
|
||||
return str.replace(templateSubstitutionRegExp, "\\${");
|
||||
}
|
||||
|
||||
// This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator,
|
||||
// paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in
|
||||
// the language service. These characters should be escaped when printing, and if any characters are added,
|
||||
@@ -4466,8 +4477,7 @@ namespace ts {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
export interface MutateMapOptions<T, U> {
|
||||
createNewValue(key: string, valueInNewMap: U): T;
|
||||
export interface MutateMapSkippingNewValuesOptions<T, U> {
|
||||
onDeleteValue(existingValue: T, key: string): void;
|
||||
|
||||
/**
|
||||
@@ -4482,8 +4492,12 @@ namespace ts {
|
||||
/**
|
||||
* Mutates the map with newMap such that keys in map will be same as newMap.
|
||||
*/
|
||||
export function mutateMap<T, U>(map: Map<T>, newMap: ReadonlyMap<U>, options: MutateMapOptions<T, U>) {
|
||||
const { createNewValue, onDeleteValue, onExistingValue } = options;
|
||||
export function mutateMapSkippingNewValues<T, U>(
|
||||
map: Map<T>,
|
||||
newMap: ReadonlyMap<U>,
|
||||
options: MutateMapSkippingNewValuesOptions<T, U>
|
||||
) {
|
||||
const { onDeleteValue, onExistingValue } = options;
|
||||
// Needs update
|
||||
map.forEach((existingValue, key) => {
|
||||
const valueInNewMap = newMap.get(key);
|
||||
@@ -4497,7 +4511,20 @@ namespace ts {
|
||||
onExistingValue(existingValue, valueInNewMap, key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export interface MutateMapOptions<T, U> extends MutateMapSkippingNewValuesOptions<T, U> {
|
||||
createNewValue(key: string, valueInNewMap: U): T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutates the map with newMap such that keys in map will be same as newMap.
|
||||
*/
|
||||
export function mutateMap<T, U>(map: Map<T>, newMap: ReadonlyMap<U>, options: MutateMapOptions<T, U>) {
|
||||
// Needs update
|
||||
mutateMapSkippingNewValues(map, newMap, options);
|
||||
|
||||
const { createNewValue } = options;
|
||||
// Add new values that are not already present
|
||||
newMap.forEach((valueInNewMap, key) => {
|
||||
if (!map.has(key)) {
|
||||
@@ -5091,7 +5118,7 @@ namespace ts {
|
||||
* attempt to draw the name from the node the declaration is on (as that declaration is what its' symbol
|
||||
* will be merged with)
|
||||
*/
|
||||
function nameForNamelessJSDocTypedef(declaration: JSDocTypedefTag): Identifier | undefined {
|
||||
function nameForNamelessJSDocTypedef(declaration: JSDocTypedefTag | JSDocEnumTag): Identifier | undefined {
|
||||
const hostNode = declaration.parent.parent;
|
||||
if (!hostNode) {
|
||||
return undefined;
|
||||
@@ -5108,7 +5135,10 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
const expr = hostNode.expression;
|
||||
let expr = hostNode.expression;
|
||||
if (expr.kind === SyntaxKind.BinaryExpression && (expr as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
expr = (expr as BinaryExpression).left;
|
||||
}
|
||||
switch (expr.kind) {
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return (expr as PropertyAccessExpression).name;
|
||||
@@ -5177,6 +5207,8 @@ namespace ts {
|
||||
}
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return getNameOfJSDocTypedef(declaration as JSDocTypedefTag);
|
||||
case SyntaxKind.JSDocEnumTag:
|
||||
return nameForNamelessJSDocTypedef(declaration as JSDocEnumTag);
|
||||
case SyntaxKind.ExportAssignment: {
|
||||
const { expression } = declaration as ExportAssignment;
|
||||
return isIdentifier(expression) ? expression : undefined;
|
||||
|
||||
@@ -538,9 +538,9 @@ namespace ts {
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
|
||||
/** If provided, used to resolve the module names, otherwise typescript's default module resolution */
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference): (ResolvedModule | undefined)[];
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
}
|
||||
/** Internal interface used to wire emit through same host */
|
||||
|
||||
@@ -744,10 +744,10 @@ namespace ts {
|
||||
);
|
||||
// Resolve module using host module resolution strategy if provided otherwise use resolution cache to resolve module names
|
||||
compilerHost.resolveModuleNames = host.resolveModuleNames ?
|
||||
((moduleNames, containingFile, reusedNames, redirectedReference) => host.resolveModuleNames!(moduleNames, containingFile, reusedNames, redirectedReference)) :
|
||||
((...args) => host.resolveModuleNames!(...args)) :
|
||||
((moduleNames, containingFile, reusedNames, redirectedReference) => resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference));
|
||||
compilerHost.resolveTypeReferenceDirectives = host.resolveTypeReferenceDirectives ?
|
||||
((typeDirectiveNames, containingFile, redirectedReference) => host.resolveTypeReferenceDirectives!(typeDirectiveNames, containingFile, redirectedReference)) :
|
||||
((...args) => host.resolveTypeReferenceDirectives!(...args)) :
|
||||
((typeDirectiveNames, containingFile, redirectedReference) => resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference));
|
||||
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
|
||||
|
||||
|
||||
@@ -344,7 +344,8 @@ namespace FourSlash {
|
||||
"getDocumentHighlights",
|
||||
];
|
||||
const proxy = {} as ts.LanguageService;
|
||||
for (const k in ls) {
|
||||
const keys = ts.getAllKeys(ls);
|
||||
for (const k of keys) {
|
||||
const key = k as keyof typeof ls;
|
||||
if (cacheableMembers.indexOf(key) === -1) {
|
||||
proxy[key] = (...args: any[]) => (ls[key] as Function)(...args);
|
||||
@@ -2325,7 +2326,10 @@ namespace FourSlash {
|
||||
public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) {
|
||||
this.goToMarker(markerName);
|
||||
|
||||
const details = this.getCompletionEntryDetails(options.name, options.source, options.preferences)!;
|
||||
const details = this.getCompletionEntryDetails(options.name, options.source, options.preferences);
|
||||
if (!details) {
|
||||
return this.raiseError(`No completions were found for the given name, source, and preferences.`);
|
||||
}
|
||||
const codeActions = details.codeActions!;
|
||||
if (codeActions.length !== 1) {
|
||||
this.raiseError(`Expected one code action, got ${codeActions.length}`);
|
||||
@@ -2434,7 +2438,7 @@ namespace FourSlash {
|
||||
const oldText = this.tryGetFileContent(change.fileName);
|
||||
ts.Debug.assert(!!change.isNewFile === (oldText === undefined));
|
||||
const newContent = change.isNewFile ? ts.first(change.textChanges).newText : ts.textChanges.applyChanges(oldText!, change.textChanges);
|
||||
assert.equal(newContent, expectedNewContent);
|
||||
assert.equal(newContent, expectedNewContent, `String mis-matched in file ${change.fileName}`);
|
||||
}
|
||||
for (const newFileName in newFileContent) {
|
||||
ts.Debug.assert(changes.some(c => c.fileName === newFileName), "No change in file", () => newFileName);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Utils {
|
||||
|
||||
export function byteLength(s: string, encoding?: string): number {
|
||||
// stub implementation if Buffer is not available (in-browser case)
|
||||
return Buffer.byteLength(s, encoding);
|
||||
return Buffer.byteLength(s, encoding as ts.BufferEncoding | undefined);
|
||||
}
|
||||
|
||||
export function evalFile(fileContents: string, fileName: string, nodeContext?: any) {
|
||||
@@ -726,6 +726,7 @@ namespace Harness {
|
||||
includeBuiltFile?: string;
|
||||
baselineFile?: string;
|
||||
libFiles?: string;
|
||||
noTypesAndSymbols?: boolean;
|
||||
}
|
||||
|
||||
// Additional options not already in ts.optionDeclarations
|
||||
@@ -742,6 +743,7 @@ namespace Harness {
|
||||
{ name: "currentDirectory", type: "string" },
|
||||
{ name: "symlink", type: "string" },
|
||||
{ name: "link", type: "string" },
|
||||
{ name: "noTypesAndSymbols", type: "boolean" },
|
||||
// Emitted js baseline will print full paths for every output file
|
||||
{ name: "fullEmitPaths", type: "boolean" }
|
||||
];
|
||||
|
||||
@@ -97,7 +97,7 @@ class TypeWriterWalker {
|
||||
if (!isSymbolWalk) {
|
||||
// Don't try to get the type of something that's already a type.
|
||||
// Exception for `T` in `type T = something` because that may evaluate to some interesting type.
|
||||
if (ts.isPartOfTypeNode(node) || ts.isIdentifier(node) && !(ts.getMeaningFromDeclaration(node.parent) & ts.SemanticMeaning.Value) && !(ts.isTypeAlias(node.parent) && node.parent.name === node)) {
|
||||
if (ts.isPartOfTypeNode(node) || ts.isIdentifier(node) && !(ts.getMeaningFromDeclaration(node.parent) & ts.SemanticMeaning.Value) && !(ts.isTypeAliasDeclaration(node.parent) && node.parent.name === node)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -314,6 +314,11 @@ interface Array<T> {}`
|
||||
invokeFileDeleteCreateAsPartInsteadOfChange: boolean;
|
||||
}
|
||||
|
||||
export enum Tsc_WatchFile {
|
||||
DynamicPolling = "DynamicPriorityPolling",
|
||||
SingleFileWatcherPerName = "SingleFileWatcherPerName"
|
||||
}
|
||||
|
||||
export enum Tsc_WatchDirectory {
|
||||
WatchFile = "RecursiveDirectoryUsingFsWatchFile",
|
||||
NonRecursiveWatchDirectory = "RecursiveDirectoryUsingNonRecursiveWatchDirectory",
|
||||
@@ -339,7 +344,7 @@ interface Array<T> {}`
|
||||
readonly watchedFiles = createMultiMap<TestFileWatcher>();
|
||||
private readonly executingFilePath: string;
|
||||
private readonly currentDirectory: string;
|
||||
private readonly dynamicPriorityWatchFile: HostWatchFile | undefined;
|
||||
private readonly customWatchFile: HostWatchFile | undefined;
|
||||
private readonly customRecursiveWatchDirectory: HostWatchDirectory | undefined;
|
||||
public require: ((initialPath: string, moduleName: string) => server.RequireResult) | undefined;
|
||||
|
||||
@@ -349,9 +354,23 @@ interface Array<T> {}`
|
||||
this.executingFilePath = this.getHostSpecificPath(executingFilePath);
|
||||
this.currentDirectory = this.getHostSpecificPath(currentDirectory);
|
||||
this.reloadFS(fileOrFolderorSymLinkList);
|
||||
this.dynamicPriorityWatchFile = this.environmentVariables && this.environmentVariables.get("TSC_WATCHFILE") === "DynamicPriorityPolling" ?
|
||||
createDynamicPriorityPollingWatchFile(this) :
|
||||
undefined;
|
||||
const tscWatchFile = this.environmentVariables && this.environmentVariables.get("TSC_WATCHFILE") as Tsc_WatchFile;
|
||||
switch (tscWatchFile) {
|
||||
case Tsc_WatchFile.DynamicPolling:
|
||||
this.customWatchFile = createDynamicPriorityPollingWatchFile(this);
|
||||
break;
|
||||
case Tsc_WatchFile.SingleFileWatcherPerName:
|
||||
this.customWatchFile = createSingleFileWatcherPerName(
|
||||
this.watchFileWorker.bind(this),
|
||||
this.useCaseSensitiveFileNames
|
||||
);
|
||||
break;
|
||||
case undefined:
|
||||
break;
|
||||
default:
|
||||
Debug.assertNever(tscWatchFile);
|
||||
}
|
||||
|
||||
const tscWatchDirectory = this.environmentVariables && this.environmentVariables.get("TSC_WATCHDIRECTORY") as Tsc_WatchDirectory;
|
||||
if (tscWatchDirectory === Tsc_WatchDirectory.WatchFile) {
|
||||
const watchDirectory: HostWatchDirectory = (directory, cb) => this.watchFile(directory, () => cb(directory), PollingInterval.Medium);
|
||||
@@ -405,7 +424,7 @@ interface Array<T> {}`
|
||||
return s;
|
||||
}
|
||||
|
||||
private now() {
|
||||
now() {
|
||||
this.time += timeIncrements;
|
||||
return new Date(this.time);
|
||||
}
|
||||
@@ -854,10 +873,14 @@ interface Array<T> {}`
|
||||
}
|
||||
|
||||
watchFile(fileName: string, cb: FileWatcherCallback, pollingInterval: number) {
|
||||
if (this.dynamicPriorityWatchFile) {
|
||||
return this.dynamicPriorityWatchFile(fileName, cb, pollingInterval);
|
||||
if (this.customWatchFile) {
|
||||
return this.customWatchFile(fileName, cb, pollingInterval);
|
||||
}
|
||||
|
||||
return this.watchFileWorker(fileName, cb);
|
||||
}
|
||||
|
||||
private watchFileWorker(fileName: string, cb: FileWatcherCallback) {
|
||||
const path = this.toFullPath(fileName);
|
||||
const callback: TestFileWatcher = { fileName, cb };
|
||||
this.watchedFiles.add(path, callback);
|
||||
|
||||
@@ -284,6 +284,10 @@ namespace ts.server {
|
||||
configFileErrors?: ReadonlyArray<Diagnostic>;
|
||||
}
|
||||
|
||||
interface AssignProjectResult extends OpenConfiguredProjectResult {
|
||||
defaultConfigProject: ConfiguredProject | undefined;
|
||||
}
|
||||
|
||||
interface FilePropertyReader<T> {
|
||||
getFileName(f: T): string;
|
||||
getScriptKind(f: T, extraFileExtensions?: FileExtensionInfo[]): ScriptKind;
|
||||
@@ -2635,10 +2639,11 @@ namespace ts.server {
|
||||
return info;
|
||||
}
|
||||
|
||||
private assignProjectToOpenedScriptInfo(info: ScriptInfo): OpenConfiguredProjectResult {
|
||||
private assignProjectToOpenedScriptInfo(info: ScriptInfo): AssignProjectResult {
|
||||
let configFileName: NormalizedPath | undefined;
|
||||
let configFileErrors: ReadonlyArray<Diagnostic> | undefined;
|
||||
let project: ConfiguredProject | ExternalProject | undefined = this.findExternalProjectContainingOpenScriptInfo(info);
|
||||
let defaultConfigProject: ConfiguredProject | undefined;
|
||||
if (!project && !this.syntaxOnly) { // Checking syntaxOnly is an optimization
|
||||
configFileName = this.getConfigFileNameForFile(info);
|
||||
if (configFileName) {
|
||||
@@ -2659,6 +2664,7 @@ namespace ts.server {
|
||||
// Ensure project is ready to check if it contains opened script info
|
||||
updateProjectIfDirty(project);
|
||||
}
|
||||
defaultConfigProject = project;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2678,13 +2684,13 @@ namespace ts.server {
|
||||
this.assignOrphanScriptInfoToInferredProject(info, this.openFiles.get(info.path));
|
||||
}
|
||||
Debug.assert(!info.isOrphan());
|
||||
return { configFileName, configFileErrors };
|
||||
return { configFileName, configFileErrors, defaultConfigProject };
|
||||
}
|
||||
|
||||
private cleanupAfterOpeningFile() {
|
||||
private cleanupAfterOpeningFile(toRetainConfigProjects: ConfiguredProject[] | ConfiguredProject | undefined) {
|
||||
// This was postponed from closeOpenFile to after opening next file,
|
||||
// so that we can reuse the project if we need to right away
|
||||
this.removeOrphanConfiguredProjects();
|
||||
this.removeOrphanConfiguredProjects(toRetainConfigProjects);
|
||||
|
||||
// Remove orphan inferred projects now that we have reused projects
|
||||
// We need to create a duplicate because we cant guarantee order after removal
|
||||
@@ -2705,14 +2711,22 @@ namespace ts.server {
|
||||
|
||||
openClientFileWithNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, projectRootPath?: NormalizedPath): OpenConfiguredProjectResult {
|
||||
const info = this.getOrCreateOpenScriptInfo(fileName, fileContent, scriptKind, hasMixedContent, projectRootPath);
|
||||
const result = this.assignProjectToOpenedScriptInfo(info);
|
||||
this.cleanupAfterOpeningFile();
|
||||
const { defaultConfigProject, ...result } = this.assignProjectToOpenedScriptInfo(info);
|
||||
this.cleanupAfterOpeningFile(defaultConfigProject);
|
||||
this.telemetryOnOpenFile(info);
|
||||
return result;
|
||||
}
|
||||
|
||||
private removeOrphanConfiguredProjects() {
|
||||
private removeOrphanConfiguredProjects(toRetainConfiguredProjects: ConfiguredProject[] | ConfiguredProject | undefined) {
|
||||
const toRemoveConfiguredProjects = cloneMap(this.configuredProjects);
|
||||
if (toRetainConfiguredProjects) {
|
||||
if (isArray(toRetainConfiguredProjects)) {
|
||||
toRetainConfiguredProjects.forEach(retainConfiguredProject);
|
||||
}
|
||||
else {
|
||||
retainConfiguredProject(toRetainConfiguredProjects);
|
||||
}
|
||||
}
|
||||
|
||||
// Do not remove configured projects that are used as original projects of other
|
||||
this.inferredProjects.forEach(markOriginalProjectsAsUsed);
|
||||
@@ -2720,7 +2734,7 @@ namespace ts.server {
|
||||
this.configuredProjects.forEach(project => {
|
||||
// If project has open ref (there are more than zero references from external project/open file), keep it alive as well as any project it references
|
||||
if (project.hasOpenRef()) {
|
||||
toRemoveConfiguredProjects.delete(project.canonicalConfigFilePath);
|
||||
retainConfiguredProject(project);
|
||||
markOriginalProjectsAsUsed(project);
|
||||
}
|
||||
else {
|
||||
@@ -2729,7 +2743,7 @@ namespace ts.server {
|
||||
if (ref) {
|
||||
const refProject = this.configuredProjects.get(ref.sourceFile.path);
|
||||
if (refProject && refProject.hasOpenRef()) {
|
||||
toRemoveConfiguredProjects.delete(project.canonicalConfigFilePath);
|
||||
retainConfiguredProject(project);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -2744,6 +2758,10 @@ namespace ts.server {
|
||||
project.originalConfiguredProjects.forEach((_value, configuredProjectPath) => toRemoveConfiguredProjects.delete(configuredProjectPath));
|
||||
}
|
||||
}
|
||||
|
||||
function retainConfiguredProject(project: ConfiguredProject) {
|
||||
toRemoveConfiguredProjects.delete(project.canonicalConfigFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
private removeOrphanScriptInfos() {
|
||||
@@ -2886,8 +2904,9 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
// All the script infos now exist, so ok to go update projects for open files
|
||||
let defaultConfigProjects: ConfiguredProject[] | undefined;
|
||||
if (openScriptInfos) {
|
||||
openScriptInfos.forEach(info => this.assignProjectToOpenedScriptInfo(info));
|
||||
defaultConfigProjects = mapDefined(openScriptInfos, info => this.assignProjectToOpenedScriptInfo(info).defaultConfigProject);
|
||||
}
|
||||
|
||||
// While closing files there could be open files that needed assigning new inferred projects, do it now
|
||||
@@ -2896,7 +2915,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
// Cleanup projects
|
||||
this.cleanupAfterOpeningFile();
|
||||
this.cleanupAfterOpeningFile(defaultConfigProjects);
|
||||
|
||||
// Telemetry
|
||||
forEach(openScriptInfos, info => this.telemetryOnOpenFile(info));
|
||||
|
||||
@@ -1275,7 +1275,7 @@ namespace ts.server {
|
||||
private enableProxy(pluginModuleFactory: PluginModuleFactory, configEntry: PluginImport) {
|
||||
try {
|
||||
if (typeof pluginModuleFactory !== "function") {
|
||||
this.projectService.logger.info(`Skipped loading plugin ${configEntry.name} because it did expose a proper factory function`);
|
||||
this.projectService.logger.info(`Skipped loading plugin ${configEntry.name} because it did not expose a proper factory function`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -684,6 +684,11 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (kind === SyntaxKind.SingleLineCommentTrivia) {
|
||||
if (tryClassifyTripleSlashComment(start, width)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Simple comment. Just add as is.
|
||||
pushCommentRange(start, width);
|
||||
@@ -756,6 +761,84 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function tryClassifyTripleSlashComment(start: number, width: number): boolean {
|
||||
const tripleSlashXMLCommentRegEx = /^(\/\/\/\s*)(<)(?:(\S+)((?:[^/]|\/[^>])*)(\/>)?)?/im;
|
||||
const attributeRegex = /(\S+)(\s*)(=)(\s*)('[^']+'|"[^"]+")/img;
|
||||
|
||||
const text = sourceFile.text.substr(start, width);
|
||||
const match = tripleSlashXMLCommentRegEx.exec(text);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let pos = start;
|
||||
|
||||
pushCommentRange(pos, match[1].length); // ///
|
||||
pos += match[1].length;
|
||||
|
||||
pushClassification(pos, match[2].length, ClassificationType.punctuation); // <
|
||||
pos += match[2].length;
|
||||
|
||||
if (!match[3]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pushClassification(pos, match[3].length, ClassificationType.jsxSelfClosingTagName); // element name
|
||||
pos += match[3].length;
|
||||
|
||||
const attrText = match[4];
|
||||
let attrPos = pos;
|
||||
while (true) {
|
||||
const attrMatch = attributeRegex.exec(attrText);
|
||||
if (!attrMatch) {
|
||||
break;
|
||||
}
|
||||
|
||||
const newAttrPos = pos + attrMatch.index;
|
||||
if (newAttrPos > attrPos) {
|
||||
pushCommentRange(attrPos, newAttrPos - attrPos);
|
||||
attrPos = newAttrPos;
|
||||
}
|
||||
|
||||
pushClassification(attrPos, attrMatch[1].length, ClassificationType.jsxAttribute); // attribute name
|
||||
attrPos += attrMatch[1].length;
|
||||
|
||||
if (attrMatch[2].length) {
|
||||
pushCommentRange(attrPos, attrMatch[2].length); // whitespace
|
||||
attrPos += attrMatch[2].length;
|
||||
}
|
||||
|
||||
pushClassification(attrPos, attrMatch[3].length, ClassificationType.operator); // =
|
||||
attrPos += attrMatch[3].length;
|
||||
|
||||
if (attrMatch[4].length) {
|
||||
pushCommentRange(attrPos, attrMatch[4].length); // whitespace
|
||||
attrPos += attrMatch[4].length;
|
||||
}
|
||||
|
||||
pushClassification(attrPos, attrMatch[5].length, ClassificationType.jsxAttributeStringLiteralValue); // attribute value
|
||||
attrPos += attrMatch[5].length;
|
||||
}
|
||||
|
||||
pos += match[4].length;
|
||||
|
||||
if (pos > attrPos) {
|
||||
pushCommentRange(attrPos, pos - attrPos);
|
||||
}
|
||||
|
||||
if (match[5]) {
|
||||
pushClassification(pos, match[5].length, ClassificationType.punctuation); // />
|
||||
pos += match[5].length;
|
||||
}
|
||||
|
||||
const end = start + width;
|
||||
if (pos < end) {
|
||||
pushCommentRange(pos, end - pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function processJSDocTemplateTag(tag: JSDocTemplateTag) {
|
||||
for (const child of tag.getChildren()) {
|
||||
processElement(child);
|
||||
|
||||
@@ -135,7 +135,8 @@ namespace ts.codefix {
|
||||
Named,
|
||||
Default,
|
||||
Namespace,
|
||||
Equals
|
||||
Equals,
|
||||
ConstEquals
|
||||
}
|
||||
|
||||
/** Information about how a symbol is exported from a module. (We don't need to store the exported symbol, just its module.) */
|
||||
@@ -163,7 +164,7 @@ namespace ts.codefix {
|
||||
position: number,
|
||||
preferences: UserPreferences,
|
||||
): { readonly moduleSpecifier: string, readonly codeAction: CodeAction } {
|
||||
const exportInfos = getAllReExportingModules(exportedSymbol, moduleSymbol, symbolName, sourceFile, program.getCompilerOptions(), program.getTypeChecker(), program.getSourceFiles());
|
||||
const exportInfos = getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, sourceFile, program.getCompilerOptions(), program.getTypeChecker(), program.getSourceFiles());
|
||||
Debug.assert(exportInfos.some(info => info.moduleSymbol === moduleSymbol));
|
||||
// We sort the best codefixes first, so taking `first` is best for completions.
|
||||
const moduleSpecifier = first(getNewImportInfos(program, sourceFile, position, exportInfos, host, preferences)).moduleSpecifier;
|
||||
@@ -175,7 +176,7 @@ namespace ts.codefix {
|
||||
return { description, changes, commands };
|
||||
}
|
||||
|
||||
function getAllReExportingModules(exportedSymbol: Symbol, exportingModuleSymbol: Symbol, symbolName: string, sourceFile: SourceFile, compilerOptions: CompilerOptions, checker: TypeChecker, allSourceFiles: ReadonlyArray<SourceFile>): ReadonlyArray<SymbolExportInfo> {
|
||||
function getAllReExportingModules(importingFile: SourceFile, exportedSymbol: Symbol, exportingModuleSymbol: Symbol, symbolName: string, sourceFile: SourceFile, compilerOptions: CompilerOptions, checker: TypeChecker, allSourceFiles: ReadonlyArray<SourceFile>): ReadonlyArray<SymbolExportInfo> {
|
||||
const result: SymbolExportInfo[] = [];
|
||||
forEachExternalModule(checker, allSourceFiles, (moduleSymbol, moduleFile) => {
|
||||
// Don't import from a re-export when looking "up" like to `./index` or `../index`.
|
||||
@@ -183,7 +184,7 @@ namespace ts.codefix {
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
|
||||
const defaultInfo = getDefaultLikeExportInfo(importingFile, moduleSymbol, checker, compilerOptions);
|
||||
if (defaultInfo && defaultInfo.name === symbolName && skipAlias(defaultInfo.symbol, checker) === exportedSymbol) {
|
||||
result.push({ moduleSymbol, importKind: defaultInfo.kind, exportedSymbolIsTypeOnly: isTypeOnlySymbol(defaultInfo.symbol, checker) });
|
||||
}
|
||||
@@ -329,7 +330,7 @@ namespace ts.codefix {
|
||||
if (!umdSymbol) return undefined;
|
||||
const symbol = checker.getAliasedSymbol(umdSymbol);
|
||||
const symbolName = umdSymbol.name;
|
||||
const exportInfos: ReadonlyArray<SymbolExportInfo> = [{ moduleSymbol: symbol, importKind: getUmdImportKind(program.getCompilerOptions()), exportedSymbolIsTypeOnly: false }];
|
||||
const exportInfos: ReadonlyArray<SymbolExportInfo> = [{ moduleSymbol: symbol, importKind: getUmdImportKind(sourceFile, program.getCompilerOptions()), exportedSymbolIsTypeOnly: false }];
|
||||
const fixes = getFixForImport(exportInfos, symbolName, isIdentifier(token) ? token.getStart(sourceFile) : undefined, program, sourceFile, host, preferences);
|
||||
return { fixes, symbolName };
|
||||
}
|
||||
@@ -345,7 +346,7 @@ namespace ts.codefix {
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function getUmdImportKind(compilerOptions: CompilerOptions): ImportKind {
|
||||
function getUmdImportKind(importingFile: SourceFile, compilerOptions: CompilerOptions): ImportKind {
|
||||
// Import a synthetic `default` if enabled.
|
||||
if (getAllowSyntheticDefaultImports(compilerOptions)) {
|
||||
return ImportKind.Default;
|
||||
@@ -357,7 +358,10 @@ namespace ts.codefix {
|
||||
case ModuleKind.AMD:
|
||||
case ModuleKind.CommonJS:
|
||||
case ModuleKind.UMD:
|
||||
return ImportKind.Equals;
|
||||
if (isInJSFile(importingFile)) {
|
||||
return isExternalModule(importingFile) ? ImportKind.Namespace : ImportKind.ConstEquals;
|
||||
}
|
||||
return ImportKind.Equals;
|
||||
case ModuleKind.System:
|
||||
case ModuleKind.ES2015:
|
||||
case ModuleKind.ESNext:
|
||||
@@ -403,7 +407,7 @@ namespace ts.codefix {
|
||||
forEachExternalModuleToImportFrom(checker, sourceFile, program.getSourceFiles(), moduleSymbol => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, program.getCompilerOptions());
|
||||
const defaultInfo = getDefaultLikeExportInfo(sourceFile, moduleSymbol, checker, program.getCompilerOptions());
|
||||
if (defaultInfo && defaultInfo.name === symbolName && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
|
||||
addSymbol(moduleSymbol, defaultInfo.symbol, defaultInfo.kind);
|
||||
}
|
||||
@@ -418,20 +422,41 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
function getDefaultLikeExportInfo(
|
||||
moduleSymbol: Symbol, checker: TypeChecker, compilerOptions: CompilerOptions,
|
||||
): { readonly symbol: Symbol, readonly symbolForMeaning: Symbol, readonly name: string, readonly kind: ImportKind.Default | ImportKind.Equals } | undefined {
|
||||
const exported = getDefaultLikeExportWorker(moduleSymbol, checker);
|
||||
importingFile: SourceFile, moduleSymbol: Symbol, checker: TypeChecker, compilerOptions: CompilerOptions,
|
||||
): { readonly symbol: Symbol, readonly symbolForMeaning: Symbol, readonly name: string, readonly kind: ImportKind } | undefined {
|
||||
const exported = getDefaultLikeExportWorker(importingFile, moduleSymbol, checker, compilerOptions);
|
||||
if (!exported) return undefined;
|
||||
const { symbol, kind } = exported;
|
||||
const info = getDefaultExportInfoWorker(symbol, moduleSymbol, checker, compilerOptions);
|
||||
return info && { symbol, kind, ...info };
|
||||
}
|
||||
|
||||
function getDefaultLikeExportWorker(moduleSymbol: Symbol, checker: TypeChecker): { readonly symbol: Symbol, readonly kind: ImportKind.Default | ImportKind.Equals } | undefined {
|
||||
function getDefaultLikeExportWorker(importingFile: SourceFile, moduleSymbol: Symbol, checker: TypeChecker, compilerOptions: CompilerOptions): { readonly symbol: Symbol, readonly kind: ImportKind } | undefined {
|
||||
const defaultExport = checker.tryGetMemberInModuleExports(InternalSymbolName.Default, moduleSymbol);
|
||||
if (defaultExport) return { symbol: defaultExport, kind: ImportKind.Default };
|
||||
const exportEquals = checker.resolveExternalModuleSymbol(moduleSymbol);
|
||||
return exportEquals === moduleSymbol ? undefined : { symbol: exportEquals, kind: ImportKind.Equals };
|
||||
return exportEquals === moduleSymbol ? undefined : { symbol: exportEquals, kind: getExportEqualsImportKind(importingFile, compilerOptions, checker) };
|
||||
}
|
||||
|
||||
function getExportEqualsImportKind(importingFile: SourceFile, compilerOptions: CompilerOptions, checker: TypeChecker): ImportKind {
|
||||
if (getAllowSyntheticDefaultImports(compilerOptions) && getEmitModuleKind(compilerOptions) >= ModuleKind.ES2015) {
|
||||
return ImportKind.Default;
|
||||
}
|
||||
if (isInJSFile(importingFile)) {
|
||||
return isExternalModule(importingFile) ? ImportKind.Default : ImportKind.ConstEquals;
|
||||
}
|
||||
for (const statement of importingFile.statements) {
|
||||
if (isImportEqualsDeclaration(statement)) {
|
||||
return ImportKind.Equals;
|
||||
}
|
||||
if (isImportDeclaration(statement) && statement.importClause && statement.importClause.name) {
|
||||
const moduleSymbol = checker.getImmediateAliasedSymbol(statement.importClause.symbol);
|
||||
if (moduleSymbol && moduleSymbol.name !== InternalSymbolName.Default) {
|
||||
return ImportKind.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ImportKind.Equals;
|
||||
}
|
||||
|
||||
function getDefaultExportInfoWorker(defaultExport: Symbol, moduleSymbol: Symbol, checker: TypeChecker, compilerOptions: CompilerOptions): { readonly symbolForMeaning: Symbol, readonly name: string } | undefined {
|
||||
@@ -445,9 +470,12 @@ namespace ts.codefix {
|
||||
const aliased = checker.getImmediateAliasedSymbol(defaultExport);
|
||||
return aliased && getDefaultExportInfoWorker(aliased, Debug.assertDefined(aliased.parent), checker, compilerOptions);
|
||||
}
|
||||
else {
|
||||
return { symbolForMeaning: defaultExport, name: moduleSymbolToValidIdentifier(moduleSymbol, compilerOptions.target!) };
|
||||
|
||||
if (defaultExport.escapedName !== InternalSymbolName.Default &&
|
||||
defaultExport.escapedName !== InternalSymbolName.ExportEquals) {
|
||||
return { symbolForMeaning: defaultExport, name: defaultExport.getName() };
|
||||
}
|
||||
return { symbolForMeaning: defaultExport, name: moduleSymbolToValidIdentifier(moduleSymbol, compilerOptions.target!) };
|
||||
}
|
||||
|
||||
function getNameForExportDefault(symbol: Symbol): string | undefined {
|
||||
@@ -540,7 +568,10 @@ namespace ts.codefix {
|
||||
interface ImportsCollection {
|
||||
readonly defaultImport: string | undefined;
|
||||
readonly namedImports: string[];
|
||||
readonly namespaceLikeImport: { readonly importKind: ImportKind.Equals | ImportKind.Namespace, readonly name: string } | undefined;
|
||||
readonly namespaceLikeImport: {
|
||||
readonly importKind: ImportKind.Equals | ImportKind.Namespace | ImportKind.ConstEquals;
|
||||
readonly name: string;
|
||||
} | undefined;
|
||||
}
|
||||
function addNewImports(changes: textChanges.ChangeTracker, sourceFile: SourceFile, moduleSpecifier: string, quotePreference: QuotePreference, { defaultImport, namedImports, namespaceLikeImport }: ImportsCollection): void {
|
||||
const quotedModuleSpecifier = makeStringLiteral(moduleSpecifier, quotePreference);
|
||||
@@ -551,12 +582,25 @@ namespace ts.codefix {
|
||||
namedImports.map(n => createImportSpecifier(/*propertyName*/ undefined, createIdentifier(n))), moduleSpecifier, quotePreference));
|
||||
}
|
||||
if (namespaceLikeImport) {
|
||||
insertImport(changes, sourceFile, namespaceLikeImport.importKind === ImportKind.Equals
|
||||
? createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createIdentifier(namespaceLikeImport.name), createExternalModuleReference(quotedModuleSpecifier))
|
||||
: createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createImportClause(/*name*/ undefined, createNamespaceImport(createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier));
|
||||
insertImport(
|
||||
changes,
|
||||
sourceFile,
|
||||
namespaceLikeImport.importKind === ImportKind.Equals ? createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createIdentifier(namespaceLikeImport.name), createExternalModuleReference(quotedModuleSpecifier)) :
|
||||
namespaceLikeImport.importKind === ImportKind.ConstEquals ? createConstEqualsRequireDeclaration(namespaceLikeImport.name, quotedModuleSpecifier) :
|
||||
createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createImportClause(/*name*/ undefined, createNamespaceImport(createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier));
|
||||
}
|
||||
}
|
||||
|
||||
function createConstEqualsRequireDeclaration(name: string, quotedModuleSpecifier: StringLiteral): VariableStatement {
|
||||
return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([
|
||||
createVariableDeclaration(
|
||||
createIdentifier(name),
|
||||
/*type*/ undefined,
|
||||
createCall(createIdentifier("require"), /*typeArguments*/ undefined, [quotedModuleSpecifier])
|
||||
)
|
||||
], NodeFlags.Const));
|
||||
}
|
||||
|
||||
function symbolHasMeaning({ declarations }: Symbol, meaning: SemanticMeaning): boolean {
|
||||
return some(declarations, decl => !!(getMeaningFromDeclaration(decl) & meaning));
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace ts.DocumentHighlights {
|
||||
|
||||
function getNodesToSearchForModifier(declaration: Node, modifierFlag: ModifierFlags): ReadonlyArray<Node> | undefined {
|
||||
// Types of node whose children might have modifiers.
|
||||
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ClassLikeDeclaration;
|
||||
const container = declaration.parent as ModuleBlock | SourceFile | Block | CaseClause | DefaultClause | ConstructorDeclaration | MethodDeclaration | FunctionDeclaration | ObjectTypeDeclaration;
|
||||
switch (container.kind) {
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.SourceFile:
|
||||
@@ -213,11 +213,13 @@ namespace ts.DocumentHighlights {
|
||||
return [...container.parameters, ...(isClassLike(container.parent) ? container.parent.members : [])];
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
const nodes = container.members;
|
||||
|
||||
// If we're an accessibility modifier, we're in an instance member and should search
|
||||
// the constructor's parameter list for instance members as well.
|
||||
if (modifierFlag & ModifierFlags.AccessibilityModifier) {
|
||||
if (modifierFlag & (ModifierFlags.AccessibilityModifier | ModifierFlags.Readonly)) {
|
||||
const constructor = find(container.members, isConstructorDeclaration);
|
||||
if (constructor) {
|
||||
return [...nodes, ...constructor.parameters];
|
||||
|
||||
@@ -709,10 +709,28 @@ namespace ts.FindAllReferences.Core {
|
||||
return references.length ? [{ definition: { type: DefinitionKind.Symbol, symbol }, references }] : emptyArray;
|
||||
}
|
||||
|
||||
/** As in a `readonly prop: any` or `constructor(readonly prop: any)`, not a `readonly any[]`. */
|
||||
function isReadonlyTypeOperator(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.ReadonlyKeyword
|
||||
&& isTypeOperatorNode(node.parent)
|
||||
&& node.parent.operator === SyntaxKind.ReadonlyKeyword;
|
||||
}
|
||||
|
||||
/** getReferencedSymbols for special node kinds. */
|
||||
function getReferencedSymbolsSpecial(node: Node, sourceFiles: ReadonlyArray<SourceFile>, cancellationToken: CancellationToken): SymbolAndEntries[] | undefined {
|
||||
if (isTypeKeyword(node.kind)) {
|
||||
return getAllReferencesForKeyword(sourceFiles, node.kind, cancellationToken);
|
||||
// A modifier readonly (like on a property declaration) is not special;
|
||||
// a readonly type keyword (like `readonly string[]`) is.
|
||||
if (node.kind === SyntaxKind.ReadonlyKeyword && !isReadonlyTypeOperator(node)) {
|
||||
return undefined;
|
||||
}
|
||||
// Likewise, when we *are* looking for a special keyword, make sure we
|
||||
// *don’t* include readonly member modifiers.
|
||||
return getAllReferencesForKeyword(
|
||||
sourceFiles,
|
||||
node.kind,
|
||||
cancellationToken,
|
||||
node.kind === SyntaxKind.ReadonlyKeyword ? isReadonlyTypeOperator : undefined);
|
||||
}
|
||||
|
||||
// Labels
|
||||
@@ -1235,11 +1253,14 @@ namespace ts.FindAllReferences.Core {
|
||||
}
|
||||
}
|
||||
|
||||
function getAllReferencesForKeyword(sourceFiles: ReadonlyArray<SourceFile>, keywordKind: SyntaxKind, cancellationToken: CancellationToken): SymbolAndEntries[] | undefined {
|
||||
function getAllReferencesForKeyword(sourceFiles: ReadonlyArray<SourceFile>, keywordKind: SyntaxKind, cancellationToken: CancellationToken, filter?: (node: Node) => boolean): SymbolAndEntries[] | undefined {
|
||||
const references = flatMap(sourceFiles, sourceFile => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
return mapDefined(getPossibleSymbolReferenceNodes(sourceFile, tokenToString(keywordKind)!, sourceFile), referenceLocation =>
|
||||
referenceLocation.kind === keywordKind ? nodeEntry(referenceLocation) : undefined);
|
||||
return mapDefined(getPossibleSymbolReferenceNodes(sourceFile, tokenToString(keywordKind)!, sourceFile), referenceLocation => {
|
||||
if (referenceLocation.kind === keywordKind && (!filter || filter(referenceLocation))) {
|
||||
return nodeEntry(referenceLocation);
|
||||
}
|
||||
});
|
||||
});
|
||||
return references.length ? [{ definition: { type: DefinitionKind.Keyword, node: references[0].node }, references }] : undefined;
|
||||
}
|
||||
|
||||
@@ -233,20 +233,23 @@ namespace ts.GoToDefinition {
|
||||
}
|
||||
|
||||
function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node: Node): DefinitionInfo[] | undefined {
|
||||
return getConstructSignatureDefinition() || getCallSignatureDefinition() || map(symbol.declarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
|
||||
// There are cases when you extend a function by adding properties to it afterwards,
|
||||
// we want to strip those extra properties
|
||||
const filteredDeclarations = filter(symbol.declarations, d => !isAssignmentDeclaration(d) || d === symbol.valueDeclaration) || undefined;
|
||||
return getConstructSignatureDefinition() || getCallSignatureDefinition() || map(filteredDeclarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
|
||||
|
||||
function getConstructSignatureDefinition(): DefinitionInfo[] | undefined {
|
||||
// Applicable only if we are in a new expression, or we are on a constructor declaration
|
||||
// and in either case the symbol has a construct signature definition, i.e. class
|
||||
if (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) {
|
||||
const cls = find(symbol.declarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
|
||||
const cls = find(filteredDeclarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
|
||||
return getSignatureDefinition(cls.members, /*selectConstructors*/ true);
|
||||
}
|
||||
}
|
||||
|
||||
function getCallSignatureDefinition(): DefinitionInfo[] | undefined {
|
||||
return isCallOrNewExpressionTarget(node) || isNameOfFunctionDeclaration(node)
|
||||
? getSignatureDefinition(symbol.declarations, /*selectConstructors*/ false)
|
||||
? getSignatureDefinition(filteredDeclarations, /*selectConstructors*/ false)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -577,10 +577,10 @@ namespace ts.FindAllReferences {
|
||||
// If a reference is a class expression, the exported node would be its parent.
|
||||
// If a reference is a variable declaration, the exported node would be the variable statement.
|
||||
function getExportNode(parent: Node, node: Node): Node | undefined {
|
||||
if (parent.kind === SyntaxKind.VariableDeclaration) {
|
||||
const p = parent as VariableDeclaration;
|
||||
return p.name !== node ? undefined :
|
||||
p.parent.kind === SyntaxKind.CatchClause ? undefined : p.parent.parent.kind === SyntaxKind.VariableStatement ? p.parent.parent : undefined;
|
||||
const declaration = isVariableDeclaration(parent) ? parent : isBindingElement(parent) ? walkUpBindingElementsAndPatterns(parent) : undefined;
|
||||
if (declaration) {
|
||||
return (parent as VariableDeclaration | BindingElement).name !== node ? undefined :
|
||||
isCatchClause(declaration.parent) ? undefined : isVariableStatement(declaration.parent.parent) ? declaration.parent.parent : undefined;
|
||||
}
|
||||
else {
|
||||
return parent;
|
||||
|
||||
@@ -71,9 +71,8 @@ namespace ts.OutliningElementsCollector {
|
||||
function addRegionOutliningSpans(sourceFile: SourceFile, out: Push<OutliningSpan>): void {
|
||||
const regions: OutliningSpan[] = [];
|
||||
const lineStarts = sourceFile.getLineStarts();
|
||||
for (let i = 0; i < lineStarts.length; i++) {
|
||||
const currentLineStart = lineStarts[i];
|
||||
const lineEnd = i + 1 === lineStarts.length ? sourceFile.getEnd() : lineStarts[i + 1] - 1;
|
||||
for (const currentLineStart of lineStarts) {
|
||||
const lineEnd = sourceFile.getLineEndOfPosition(currentLineStart);
|
||||
const lineText = sourceFile.text.substring(currentLineStart, lineEnd);
|
||||
const result = isRegionDelimiter(lineText);
|
||||
if (!result || isInComment(sourceFile, currentLineStart)) {
|
||||
|
||||
@@ -350,7 +350,11 @@ namespace ts.refactor {
|
||||
}
|
||||
if (namedBindings) {
|
||||
if (namedBindingsUnused) {
|
||||
changes.delete(sourceFile, namedBindings);
|
||||
changes.replaceNode(
|
||||
sourceFile,
|
||||
importDecl.importClause,
|
||||
updateImportClause(importDecl.importClause, name, /*namedBindings*/ undefined)
|
||||
);
|
||||
}
|
||||
else if (namedBindings.kind === SyntaxKind.NamedImports) {
|
||||
for (const element of namedBindings.elements) {
|
||||
|
||||
@@ -1238,12 +1238,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (host.resolveModuleNames) {
|
||||
compilerHost.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference) => host.resolveModuleNames!(moduleNames, containingFile, reusedNames, redirectedReference);
|
||||
compilerHost.resolveModuleNames = (...args) => host.resolveModuleNames!(...args);
|
||||
}
|
||||
if (host.resolveTypeReferenceDirectives) {
|
||||
compilerHost.resolveTypeReferenceDirectives = (typeReferenceDirectiveNames, containingFile, redirectedReference) => {
|
||||
return host.resolveTypeReferenceDirectives!(typeReferenceDirectiveNames, containingFile, redirectedReference);
|
||||
};
|
||||
compilerHost.resolveTypeReferenceDirectives = (...args) => host.resolveTypeReferenceDirectives!(...args);
|
||||
}
|
||||
|
||||
const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ts.SmartSelectionRange {
|
||||
break outer;
|
||||
}
|
||||
|
||||
if (positionShouldSnapToNode(pos, node, nextNode)) {
|
||||
if (positionShouldSnapToNode(sourceFile, pos, node)) {
|
||||
// 1. Blocks are effectively redundant with SyntaxLists.
|
||||
// 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping
|
||||
// of things that should be considered independently.
|
||||
@@ -64,6 +64,13 @@ namespace ts.SmartSelectionRange {
|
||||
parentNode = node;
|
||||
break;
|
||||
}
|
||||
|
||||
// If we made it to the end of the for loop, we’re done.
|
||||
// In practice, I’ve only seen this happen at the very end
|
||||
// of a SourceFile.
|
||||
if (i === children.length - 1) {
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,12 +97,11 @@ namespace ts.SmartSelectionRange {
|
||||
* count too, unless that position belongs to the next node. In effect, makes
|
||||
* selections able to snap to preceding tokens when the cursor is on the tail
|
||||
* end of them with only whitespace ahead.
|
||||
* @param sourceFile The source file containing the nodes.
|
||||
* @param pos The position to check.
|
||||
* @param node The candidate node to snap to.
|
||||
* @param nextNode The next sibling node in the tree.
|
||||
* @param sourceFile The source file containing the nodes.
|
||||
*/
|
||||
function positionShouldSnapToNode(pos: number, node: Node, nextNode: Node | undefined) {
|
||||
function positionShouldSnapToNode(sourceFile: SourceFile, pos: number, node: Node) {
|
||||
// Can’t use 'ts.positionBelongsToNode()' here because it cleverly accounts
|
||||
// for missing nodes, which can’t really be considered when deciding what
|
||||
// to select.
|
||||
@@ -104,9 +110,8 @@ namespace ts.SmartSelectionRange {
|
||||
return true;
|
||||
}
|
||||
const nodeEnd = node.getEnd();
|
||||
const nextNodeStart = nextNode && nextNode.getStart();
|
||||
if (nodeEnd === pos) {
|
||||
return pos !== nextNodeStart;
|
||||
return getTouchingPropertyName(sourceFile, pos).pos < node.end;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -211,9 +211,9 @@ namespace ts {
|
||||
*
|
||||
* If this is implemented, `getResolvedModuleWithFailedLookupLocationsFromCache` should be too.
|
||||
*/
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference): (ResolvedModule | undefined)[];
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
|
||||
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: boolean;
|
||||
|
||||
|
||||
@@ -58,16 +58,18 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
public checkTestCodeOutput(fileName: string, test?: CompilerFileBasedTest) {
|
||||
if (test && test.configurations) {
|
||||
if (test && ts.some(test.configurations)) {
|
||||
test.configurations.forEach(configuration => {
|
||||
describe(`${this.testSuiteName} tests for ${fileName}${configuration ? ` (${Harness.getFileBasedTestConfigurationDescription(configuration)})` : ``}`, () => {
|
||||
this.runSuite(fileName, test, configuration);
|
||||
});
|
||||
});
|
||||
}
|
||||
describe(`${this.testSuiteName} tests for ${fileName}`, () => {
|
||||
this.runSuite(fileName, test);
|
||||
});
|
||||
else {
|
||||
describe(`${this.testSuiteName} tests for ${fileName}`, () => {
|
||||
this.runSuite(fileName, test);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private runSuite(fileName: string, test?: CompilerFileBasedTest, configuration?: Harness.FileBasedTestConfiguration) {
|
||||
@@ -112,6 +114,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
class CompilerTest {
|
||||
private fileName: string;
|
||||
private justName: string;
|
||||
private configuredName: string;
|
||||
private lastUnit: Harness.TestCaseParser.TestUnitData;
|
||||
private harnessSettings: Harness.TestCaseParser.CompilerSettings;
|
||||
private hasNonDtsFiles: boolean;
|
||||
@@ -126,6 +129,25 @@ class CompilerTest {
|
||||
constructor(fileName: string, testCaseContent?: Harness.TestCaseParser.TestCaseContent, configurationOverrides?: Harness.TestCaseParser.CompilerSettings) {
|
||||
this.fileName = fileName;
|
||||
this.justName = vpath.basename(fileName);
|
||||
this.configuredName = this.justName;
|
||||
if (configurationOverrides) {
|
||||
let configuredName = "";
|
||||
const keys = Object
|
||||
.keys(configurationOverrides)
|
||||
.map(k => k.toLowerCase())
|
||||
.sort();
|
||||
for (const key of keys) {
|
||||
if (configuredName) {
|
||||
configuredName += ",";
|
||||
}
|
||||
configuredName += `${key}=${configurationOverrides[key].toLowerCase()}`;
|
||||
}
|
||||
if (configuredName) {
|
||||
const extname = vpath.extname(this.justName);
|
||||
const basename = vpath.basename(this.justName, extname, /*ignoreCase*/ true);
|
||||
this.configuredName = `${basename}(${configuredName})${extname}`;
|
||||
}
|
||||
}
|
||||
|
||||
const rootDir = fileName.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(fileName) + "/";
|
||||
|
||||
@@ -205,7 +227,7 @@ class CompilerTest {
|
||||
public verifyDiagnostics() {
|
||||
// check errors
|
||||
Harness.Compiler.doErrorBaseline(
|
||||
this.justName,
|
||||
this.configuredName,
|
||||
this.tsConfigFiles.concat(this.toBeCompiled, this.otherFiles),
|
||||
this.result.diagnostics,
|
||||
!!this.options.pretty);
|
||||
@@ -213,7 +235,7 @@ class CompilerTest {
|
||||
|
||||
public verifyModuleResolution() {
|
||||
if (this.options.traceResolution) {
|
||||
Harness.Baseline.runBaseline(this.justName.replace(/\.tsx?$/, ".trace.json"),
|
||||
Harness.Baseline.runBaseline(this.configuredName.replace(/\.tsx?$/, ".trace.json"),
|
||||
JSON.stringify(this.result.traces.map(utils.sanitizeTraceResolutionLogEntry), undefined, 4));
|
||||
}
|
||||
}
|
||||
@@ -225,14 +247,14 @@ class CompilerTest {
|
||||
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
|
||||
? null // tslint:disable-line no-null-keyword
|
||||
: record;
|
||||
Harness.Baseline.runBaseline(this.justName.replace(/\.tsx?$/, ".sourcemap.txt"), baseline);
|
||||
Harness.Baseline.runBaseline(this.configuredName.replace(/\.tsx?$/, ".sourcemap.txt"), baseline);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyJavaScriptOutput() {
|
||||
if (this.hasNonDtsFiles) {
|
||||
Harness.Compiler.doJsEmitBaseline(
|
||||
this.justName,
|
||||
this.configuredName,
|
||||
this.fileName,
|
||||
this.options,
|
||||
this.result,
|
||||
@@ -245,7 +267,7 @@ class CompilerTest {
|
||||
|
||||
public verifySourceMapOutput() {
|
||||
Harness.Compiler.doSourcemapBaseline(
|
||||
this.justName,
|
||||
this.configuredName,
|
||||
this.options,
|
||||
this.result,
|
||||
this.harnessSettings);
|
||||
@@ -256,8 +278,15 @@ class CompilerTest {
|
||||
return;
|
||||
}
|
||||
|
||||
const noTypesAndSymbols =
|
||||
this.harnessSettings.noTypesAndSymbols &&
|
||||
this.harnessSettings.noTypesAndSymbols.toLowerCase() === "true";
|
||||
if (noTypesAndSymbols) {
|
||||
return;
|
||||
}
|
||||
|
||||
Harness.Compiler.doTypeAndSymbolBaseline(
|
||||
this.justName,
|
||||
this.configuredName,
|
||||
this.result.program!,
|
||||
this.toBeCompiled.concat(this.otherFiles).filter(file => !!this.result.program!.getSourceFile(file.unitName)),
|
||||
/*opts*/ undefined,
|
||||
|
||||
@@ -5,7 +5,7 @@ const del: typeof import("del") = require("del");
|
||||
interface ExecResult {
|
||||
stdout: Buffer;
|
||||
stderr: Buffer;
|
||||
status: number;
|
||||
status: number | null;
|
||||
}
|
||||
|
||||
interface UserConfig {
|
||||
@@ -185,7 +185,8 @@ function stripRushStageNumbers(result: string): string {
|
||||
* so we purge as much of the gulp output as we can
|
||||
*/
|
||||
function sanitizeUnimportantGulpOutput(result: string): string {
|
||||
return result.replace(/^.*(\] (Starting)|(Finished)).*$/gm, "") // task start/end messages (nondeterministic order)
|
||||
return result.replace(/^.*(\] (Starting)|(Finished)).*$/gm, "") // "gulp" task start/end messages (nondeterministic order)
|
||||
.replace(/^.*(\] . (finished)|(started)).*$/gm, "") // "just" task start/end messages (nondeterministic order)
|
||||
.replace(/^.*\] Respawned to PID: \d+.*$/gm, "") // PID of child is OS and system-load dependent (likely stableish in a container but still dangerous)
|
||||
.replace(/\n+/g, "\n");
|
||||
}
|
||||
@@ -193,14 +194,17 @@ function sanitizeUnimportantGulpOutput(result: string): string {
|
||||
function sanitizeTimestamps(result: string): string {
|
||||
return result.replace(/\[\d?\d:\d\d:\d\d (A|P)M\]/g, "[XX:XX:XX XM]")
|
||||
.replace(/\[\d?\d:\d\d:\d\d\]/g, "[XX:XX:XX]")
|
||||
.replace(/\/\d+-\d+-[\d_TZ]+-debug.log/g, "\/XXXX-XX-XXXXXXXXX-debug.log")
|
||||
.replace(/\d+(\.\d+)? sec(onds?)?/g, "? seconds")
|
||||
.replace(/\d+(\.\d+)? min(utes?)?/g, "")
|
||||
.replace(/\d+(\.\d+)?( m)?s/g, "?s");
|
||||
.replace(/\d+(\.\d+)? ?m?s/g, "?s")
|
||||
.replace(/ \(\?s\)/g, "");
|
||||
}
|
||||
|
||||
function sanitizeVersionSpecifiers(result: string): string {
|
||||
return result
|
||||
.replace(/\d+.\d+.\d+-insiders.\d\d\d\d\d\d\d\d/g, "X.X.X-insiders.xxxxxxxx")
|
||||
.replace(/Rush Multi-Project Build Tool (\d+)\.\d+\.\d+/g, "Rush Multi-Project Build Tool $1.X.X")
|
||||
.replace(/([@v\()])\d+\.\d+\.\d+/g, "$1X.X.X");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@
|
||||
"unittests/semver.ts",
|
||||
"unittests/shimMap.ts",
|
||||
"unittests/transform.ts",
|
||||
"unittests/tsbuildWatchMode.ts",
|
||||
"unittests/config/commandLineParsing.ts",
|
||||
"unittests/config/configurationExtension.ts",
|
||||
"unittests/config/convertCompilerOptionsFromJson.ts",
|
||||
@@ -75,6 +74,7 @@
|
||||
"unittests/evaluation/asyncGenerator.ts",
|
||||
"unittests/evaluation/awaiter.ts",
|
||||
"unittests/evaluation/forAwaitOf.ts",
|
||||
"unittests/evaluation/forOf.ts",
|
||||
"unittests/evaluation/objectRest.ts",
|
||||
"unittests/services/cancellableLanguageServiceOperations.ts",
|
||||
"unittests/services/colorization.ts",
|
||||
@@ -103,6 +103,8 @@
|
||||
"unittests/tsbuild/resolveJsonModule.ts",
|
||||
"unittests/tsbuild/sample.ts",
|
||||
"unittests/tsbuild/transitiveReferences.ts",
|
||||
"unittests/tsbuild/watchEnvironment.ts",
|
||||
"unittests/tsbuild/watchMode.ts",
|
||||
"unittests/tscWatch/consoleClearing.ts",
|
||||
"unittests/tscWatch/emit.ts",
|
||||
"unittests/tscWatch/emitAndErrorUpdates.ts",
|
||||
@@ -130,6 +132,7 @@
|
||||
"unittests/tsserver/formatSettings.ts",
|
||||
"unittests/tsserver/getApplicableRefactors.ts",
|
||||
"unittests/tsserver/getEditsForFileRename.ts",
|
||||
"unittests/tsserver/getExportReferences.ts",
|
||||
"unittests/tsserver/importHelpers.ts",
|
||||
"unittests/tsserver/inferredProjects.ts",
|
||||
"unittests/tsserver/languageService.ts",
|
||||
|
||||
@@ -53,6 +53,26 @@ namespace ts {
|
||||
|
||||
showTSConfigCorrectly("Show TSConfig with advanced options", ["--showConfig", "--declaration", "--declarationDir", "lib", "--skipLibCheck", "--noErrorTruncation"]);
|
||||
|
||||
showTSConfigCorrectly("Show TSConfig with compileOnSave and more", ["-p", "tsconfig.json"], {
|
||||
compilerOptions: {
|
||||
esModuleInterop: true,
|
||||
target: "es5",
|
||||
module: "commonjs",
|
||||
strict: true,
|
||||
},
|
||||
compileOnSave: true,
|
||||
exclude: [
|
||||
"dist"
|
||||
],
|
||||
files: [],
|
||||
include: [
|
||||
"src/*"
|
||||
],
|
||||
references: [
|
||||
{ path: "./test" }
|
||||
],
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/Microsoft/TypeScript/issues/28836
|
||||
showTSConfigCorrectly("Show TSConfig with paths and more", ["-p", "tsconfig.json"], {
|
||||
compilerOptions: {
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
describe("unittests:: evaluation:: forOfEvaluation", () => {
|
||||
it("es5 over a array with no Symbol", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
Symbol = undefined;
|
||||
export var output = [];
|
||||
export function main() {
|
||||
let x = [1,2,3];
|
||||
|
||||
for (let value of x) {
|
||||
output.push(value);
|
||||
}
|
||||
}
|
||||
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
result.main();
|
||||
|
||||
assert.strictEqual(result.output[0], 1);
|
||||
assert.strictEqual(result.output[1], 2);
|
||||
assert.strictEqual(result.output[2], 3);
|
||||
|
||||
});
|
||||
|
||||
it("es5 over a string with no Symbol", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
Symbol = undefined;
|
||||
export var output = [];
|
||||
export function main() {
|
||||
let x = "hello";
|
||||
|
||||
for (let value of x) {
|
||||
output.push(value);
|
||||
}
|
||||
}
|
||||
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
result.main();
|
||||
|
||||
assert.strictEqual(result.output[0], "h");
|
||||
assert.strictEqual(result.output[1], "e");
|
||||
assert.strictEqual(result.output[2], "l");
|
||||
assert.strictEqual(result.output[3], "l");
|
||||
assert.strictEqual(result.output[4], "o");
|
||||
});
|
||||
|
||||
it("es5 over undefined with no Symbol", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
Symbol = undefined;
|
||||
export function main() {
|
||||
let x = undefined;
|
||||
|
||||
for (let value of x) {
|
||||
}
|
||||
}
|
||||
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
assert.throws(() => result.main(), "Symbol.iterator is not defined");
|
||||
});
|
||||
|
||||
it("es5 over undefined with Symbol", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
export function main() {
|
||||
let x = undefined;
|
||||
|
||||
for (let value of x) {
|
||||
}
|
||||
}
|
||||
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
assert.throws(() => result.main(), /cannot read property.*Symbol\(Symbol\.iterator\).*/i);
|
||||
});
|
||||
|
||||
it("es5 over object with no Symbol.iterator with no Symbol", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
Symbol = undefined;
|
||||
export function main() {
|
||||
let x = {} as any;
|
||||
|
||||
for (let value of x) {
|
||||
}
|
||||
}
|
||||
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
assert.throws(() => result.main(), "Symbol.iterator is not defined");
|
||||
});
|
||||
|
||||
it("es5 over object with no Symbol.iterator with Symbol", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
export function main() {
|
||||
let x = {} as any;
|
||||
|
||||
for (let value of x) {
|
||||
}
|
||||
}
|
||||
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
assert.throws(() => result.main(), "Object is not iterable");
|
||||
});
|
||||
|
||||
it("es5 over object with Symbol.iterator", () => {
|
||||
const result = evaluator.evaluateTypeScript(`
|
||||
export var output = [];
|
||||
export function main() {
|
||||
let thing : any = {};
|
||||
thing[Symbol.iterator] = () => {
|
||||
let i = 0;
|
||||
return { next() { i++; return this; }, value: i, done: i < 10 };
|
||||
};
|
||||
|
||||
for (let value of thing)
|
||||
{
|
||||
output.push(value)
|
||||
}
|
||||
|
||||
}`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
|
||||
|
||||
result.main();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -38,6 +38,18 @@ namespace ts {
|
||||
verifyNewLines(content, { newLine: NewLineKind.LineFeed });
|
||||
}
|
||||
|
||||
function verifyOutliningSpanNewLines(content: string, options: CompilerOptions) {
|
||||
const ls = testLSWithFiles(options, [{
|
||||
content,
|
||||
fileOptions: {},
|
||||
unitName: "input.ts"
|
||||
}]);
|
||||
const span = ls.getOutliningSpans("input.ts")[0];
|
||||
const textAfterSpanCollapse = content.substring(span.textSpan.start + span.textSpan.length);
|
||||
assert(textAfterSpanCollapse.match(options.newLine === NewLineKind.CarriageReturnLineFeed ? /\r\n/ : /[^\r]\n/), "expected to find appropriate newlines");
|
||||
assert(!textAfterSpanCollapse.match(options.newLine === NewLineKind.CarriageReturnLineFeed ? /[^\r]\n/ : /\r\n/), "expected not to find inappropriate newlines");
|
||||
}
|
||||
|
||||
it("should exist and respect provided compiler options", () => {
|
||||
verifyBothNewLines(`
|
||||
function foo() {
|
||||
@@ -45,5 +57,15 @@ namespace ts {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("should respect CRLF line endings around outlining spans", () => {
|
||||
verifyOutliningSpanNewLines("// comment not included\r\n// #region name\r\nlet x: string = \"x\";\r\n// #endregion name\r\n",
|
||||
{ newLine: NewLineKind.CarriageReturnLineFeed });
|
||||
});
|
||||
|
||||
it("should respect LF line endings around outlining spans", () => {
|
||||
verifyOutliningSpanNewLines("// comment not included\n// #region name\nlet x: string = \"x\";\n// #endregion name\n\n",
|
||||
{ newLine: NewLineKind.LineFeed });
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
namespace ts.tscWatch {
|
||||
describe("unittests:: tsbuild:: watchEnvironment:: tsbuild:: watchMode:: with different watch environments", () => {
|
||||
describe("when watchFile can create multiple watchers per file", () => {
|
||||
verifyWatchFileOnMultipleProjects(/*singleWatchPerFile*/ false);
|
||||
});
|
||||
|
||||
describe("when watchFile is single watcher per file", () => {
|
||||
verifyWatchFileOnMultipleProjects(
|
||||
/*singleWatchPerFile*/ true,
|
||||
arrayToMap(["TSC_WATCHFILE"], identity, () => TestFSWithWatch.Tsc_WatchFile.SingleFileWatcherPerName)
|
||||
);
|
||||
});
|
||||
|
||||
function verifyWatchFileOnMultipleProjects(singleWatchPerFile: boolean, environmentVariables?: Map<string>) {
|
||||
it("watchFile on same file multiple times because file is part of multiple projects", () => {
|
||||
const project = `${TestFSWithWatch.tsbuildProjectsLocation}/myproject`;
|
||||
let maxPkgs = 4;
|
||||
const configPath = `${project}/tsconfig.json`;
|
||||
const typing: File = {
|
||||
path: `${project}/typings/xterm.d.ts`,
|
||||
content: "export const typing = 10;"
|
||||
};
|
||||
|
||||
const allPkgFiles = pkgs(pkgFiles);
|
||||
const system = createWatchedSystem([libFile, typing, ...flatArray(allPkgFiles)], { currentDirectory: project, environmentVariables });
|
||||
writePkgReferences();
|
||||
const host = createSolutionBuilderWithWatchHost(system);
|
||||
const solutionBuilder = createSolutionBuilderWithWatch(host, ["tsconfig.json"], { watch: true, verbose: true });
|
||||
solutionBuilder.build();
|
||||
checkOutputErrorsInitial(system, emptyArray, /*disableConsoleClears*/ undefined, [
|
||||
`Projects in this build: \r\n${
|
||||
concatenate(
|
||||
pkgs(index => ` * pkg${index}/tsconfig.json`),
|
||||
[" * tsconfig.json"]
|
||||
).join("\r\n")}\n\n`,
|
||||
...flatArray(pkgs(index => [
|
||||
`Project 'pkg${index}/tsconfig.json' is out of date because output file 'pkg${index}/index.js' does not exist\n\n`,
|
||||
`Building project '${project}/pkg${index}/tsconfig.json'...\n\n`
|
||||
]))
|
||||
]);
|
||||
|
||||
const watchFilesDetailed = arrayToMap(flatArray(allPkgFiles), f => f.path, () => 1);
|
||||
watchFilesDetailed.set(configPath, 1);
|
||||
watchFilesDetailed.set(typing.path, singleWatchPerFile ? 1 : maxPkgs);
|
||||
checkWatchedFilesDetailed(system, watchFilesDetailed);
|
||||
system.writeFile(typing.path, `${typing.content}export const typing1 = 10;`);
|
||||
verifyInvoke();
|
||||
|
||||
// Make change
|
||||
maxPkgs--;
|
||||
writePkgReferences();
|
||||
system.checkTimeoutQueueLengthAndRun(1);
|
||||
checkOutputErrorsIncremental(system, emptyArray);
|
||||
const lastFiles = last(allPkgFiles);
|
||||
lastFiles.forEach(f => watchFilesDetailed.delete(f.path));
|
||||
watchFilesDetailed.set(typing.path, singleWatchPerFile ? 1 : maxPkgs);
|
||||
checkWatchedFilesDetailed(system, watchFilesDetailed);
|
||||
system.writeFile(typing.path, typing.content);
|
||||
verifyInvoke();
|
||||
|
||||
// Make change to remove all the watches
|
||||
maxPkgs = 0;
|
||||
writePkgReferences();
|
||||
system.checkTimeoutQueueLengthAndRun(1);
|
||||
checkOutputErrorsIncremental(system, [
|
||||
`tsconfig.json(1,10): error TS18002: The 'files' list in config file '${configPath}' is empty.\n`
|
||||
]);
|
||||
checkWatchedFilesDetailed(system, [configPath], 1);
|
||||
|
||||
system.writeFile(typing.path, `${typing.content}export const typing1 = 10;`);
|
||||
system.checkTimeoutQueueLength(0);
|
||||
|
||||
function flatArray<T>(arr: T[][]): readonly T[] {
|
||||
return flatMap(arr, identity);
|
||||
}
|
||||
function pkgs<T>(cb: (index: number) => T): T[] {
|
||||
const result: T[] = [];
|
||||
for (let index = 0; index < maxPkgs; index++) {
|
||||
result.push(cb(index));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function createPkgReference(index: number) {
|
||||
return { path: `./pkg${index}` };
|
||||
}
|
||||
function pkgFiles(index: number): File[] {
|
||||
return [
|
||||
{
|
||||
path: `${project}/pkg${index}/index.ts`,
|
||||
content: `export const pkg${index} = ${index};`
|
||||
},
|
||||
{
|
||||
path: `${project}/pkg${index}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
complerOptions: { composite: true },
|
||||
include: [
|
||||
"**/*.ts",
|
||||
"../typings/xterm.d.ts"
|
||||
]
|
||||
})
|
||||
}
|
||||
];
|
||||
}
|
||||
function writePkgReferences() {
|
||||
system.writeFile(configPath, JSON.stringify({
|
||||
files: [],
|
||||
include: [],
|
||||
references: pkgs(createPkgReference)
|
||||
}));
|
||||
}
|
||||
function verifyInvoke() {
|
||||
pkgs(() => system.checkTimeoutQueueLengthAndRun(1));
|
||||
checkOutputErrorsIncremental(system, emptyArray, /*disableConsoleClears*/ undefined, /*logsBeforeWatchDiagnostics*/ undefined, [
|
||||
...flatArray(pkgs(index => [
|
||||
`Project 'pkg${index}/tsconfig.json' is out of date because oldest output 'pkg${index}/index.js' is older than newest input 'typings/xterm.d.ts'\n\n`,
|
||||
`Building project '${project}/pkg${index}/tsconfig.json'...\n\n`,
|
||||
`Updating unchanged output timestamps of project '${project}/pkg${index}/tsconfig.json'...\n\n`
|
||||
]))
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
+58
-28
@@ -16,11 +16,19 @@ namespace ts.tscWatch {
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
export function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
|
||||
const host = createSolutionBuilderHost(system);
|
||||
host.now = system.now.bind(system);
|
||||
return ts.createSolutionBuilder(host, rootNames, defaultOptions || {});
|
||||
}
|
||||
|
||||
export function createSolutionBuilderWithWatchHost(system: WatchedSystem) {
|
||||
const host = ts.createSolutionBuilderWithWatchHost(system);
|
||||
host.now = system.now.bind(system);
|
||||
return host;
|
||||
}
|
||||
|
||||
function createSolutionBuilderWithWatch(system: TsBuildWatchSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
|
||||
const host = createSolutionBuilderWithWatchHost(system);
|
||||
const solutionBuilder = ts.createSolutionBuilderWithWatch(host, rootNames, defaultOptions || { watch: true });
|
||||
@@ -33,7 +41,7 @@ namespace ts.tscWatch {
|
||||
return [f, host.getModifiedTime(f), host.writtenFiles.has(host.toFullPath(f))] as OutputFileStamp;
|
||||
}
|
||||
|
||||
describe("unittests:: tsbuild-watch program updates", () => {
|
||||
describe("unittests:: tsbuild:: watchMode:: program updates", () => {
|
||||
const project = "sample1";
|
||||
const enum SubProject {
|
||||
core = "core",
|
||||
@@ -113,13 +121,33 @@ namespace ts.tscWatch {
|
||||
}
|
||||
}
|
||||
|
||||
const core = subProjectFiles(SubProject.core, /*anotherModuleAndSomeDecl*/ true);
|
||||
const logic = subProjectFiles(SubProject.logic);
|
||||
const tests = subProjectFiles(SubProject.tests);
|
||||
const ui = subProjectFiles(SubProject.ui);
|
||||
const allFiles: ReadonlyArray<File> = [libFile, ...core, ...logic, ...tests, ...ui];
|
||||
const testProjectExpectedWatchedFiles = [core[0], core[1], core[2]!, ...logic, ...tests].map(f => f.path.toLowerCase()); // tslint:disable-line no-unnecessary-type-assertion (TODO: type assertion should be necessary)
|
||||
const testProjectExpectedWatchedDirectoriesRecursive = [projectPath(SubProject.core), projectPath(SubProject.logic)];
|
||||
let core: SubProjectFiles;
|
||||
let logic: SubProjectFiles;
|
||||
let tests: SubProjectFiles;
|
||||
let ui: SubProjectFiles;
|
||||
let allFiles: ReadonlyArray<File>;
|
||||
let testProjectExpectedWatchedFiles: string[];
|
||||
let testProjectExpectedWatchedDirectoriesRecursive: string[];
|
||||
|
||||
before(() => {
|
||||
core = subProjectFiles(SubProject.core, /*anotherModuleAndSomeDecl*/ true);
|
||||
logic = subProjectFiles(SubProject.logic);
|
||||
tests = subProjectFiles(SubProject.tests);
|
||||
ui = subProjectFiles(SubProject.ui);
|
||||
allFiles = [libFile, ...core, ...logic, ...tests, ...ui];
|
||||
testProjectExpectedWatchedFiles = [core[0], core[1], core[2]!, ...logic, ...tests].map(f => f.path.toLowerCase()); // tslint:disable-line no-unnecessary-type-assertion (TODO: type assertion should be necessary)
|
||||
testProjectExpectedWatchedDirectoriesRecursive = [projectPath(SubProject.core), projectPath(SubProject.logic)];
|
||||
});
|
||||
|
||||
after(() => {
|
||||
core = undefined!;
|
||||
logic = undefined!;
|
||||
tests = undefined!;
|
||||
ui = undefined!;
|
||||
allFiles = undefined!;
|
||||
testProjectExpectedWatchedFiles = undefined!;
|
||||
testProjectExpectedWatchedDirectoriesRecursive = undefined!;
|
||||
});
|
||||
|
||||
function createSolutionInWatchMode(allFiles: ReadonlyArray<File>, defaultOptions?: BuildOptions, disableConsoleClears?: boolean) {
|
||||
const host = createTsBuildWatchSystem(allFiles, { currentDirectory: projectsLocation });
|
||||
@@ -172,9 +200,9 @@ namespace ts.tscWatch {
|
||||
content: `export const newFileConst = 30;`
|
||||
};
|
||||
|
||||
function verifyProjectChanges(allFiles: ReadonlyArray<File>) {
|
||||
function verifyProjectChanges(allFilesGetter: () => ReadonlyArray<File>) {
|
||||
function createSolutionInWatchModeToVerifyChanges(additionalFiles?: ReadonlyArray<[SubProject, string]>) {
|
||||
const host = createSolutionInWatchMode(allFiles);
|
||||
const host = createSolutionInWatchMode(allFilesGetter());
|
||||
return { host, verifyChangeWithFile, verifyChangeAfterTimeout, verifyWatches };
|
||||
|
||||
function verifyChangeWithFile(fileName: string, content: string, local?: boolean) {
|
||||
@@ -277,19 +305,21 @@ export class someClass2 { }`);
|
||||
}
|
||||
|
||||
describe("with simple project reference graph", () => {
|
||||
verifyProjectChanges(allFiles);
|
||||
verifyProjectChanges(() => allFiles);
|
||||
});
|
||||
|
||||
describe("with circular project reference", () => {
|
||||
const [coreTsconfig, ...otherCoreFiles] = core;
|
||||
const circularCoreConfig: File = {
|
||||
path: coreTsconfig.path,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { composite: true, declaration: true },
|
||||
references: [{ path: "../tests", circular: true }]
|
||||
})
|
||||
};
|
||||
verifyProjectChanges([libFile, circularCoreConfig, ...otherCoreFiles, ...logic, ...tests]);
|
||||
verifyProjectChanges(() => {
|
||||
const [coreTsconfig, ...otherCoreFiles] = core;
|
||||
const circularCoreConfig: File = {
|
||||
path: coreTsconfig.path,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { composite: true, declaration: true },
|
||||
references: [{ path: "../tests", circular: true }]
|
||||
})
|
||||
};
|
||||
return [libFile, circularCoreConfig, ...otherCoreFiles, ...logic, ...tests];
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -681,9 +711,9 @@ let x: string = 10;`);
|
||||
const coreIndexDts = projectFileName(SubProject.core, "index.d.ts");
|
||||
const coreAnotherModuleDts = projectFileName(SubProject.core, "anotherModule.d.ts");
|
||||
const logicIndexDts = projectFileName(SubProject.logic, "index.d.ts");
|
||||
const expectedWatchedFiles = [core[0], logic[0], ...tests, libFile].map(f => f.path).concat([coreIndexDts, coreAnotherModuleDts, logicIndexDts].map(f => f.toLowerCase()));
|
||||
const expectedWatchedFiles = () => [core[0], logic[0], ...tests, libFile].map(f => f.path).concat([coreIndexDts, coreAnotherModuleDts, logicIndexDts].map(f => f.toLowerCase()));
|
||||
const expectedWatchedDirectoriesRecursive = projectSystem.getTypeRootsFromLocation(projectPath(SubProject.tests));
|
||||
const expectedProgramFiles = [tests[1].path, libFile.path, coreIndexDts, coreAnotherModuleDts, logicIndexDts];
|
||||
const expectedProgramFiles = () => [tests[1].path, libFile.path, coreIndexDts, coreAnotherModuleDts, logicIndexDts];
|
||||
|
||||
function createSolutionAndWatchMode() {
|
||||
return createSolutionAndWatchModeOfProject(allFiles, projectsLocation, `${project}/${SubProject.tests}`, tests[0].path, getOutputFileStamps);
|
||||
@@ -694,12 +724,12 @@ let x: string = 10;`);
|
||||
}
|
||||
|
||||
function verifyWatches(host: TsBuildWatchSystem, withTsserver?: boolean) {
|
||||
verifyWatchesOfProject(host, withTsserver ? expectedWatchedFiles.filter(f => f !== tests[1].path.toLowerCase()) : expectedWatchedFiles, expectedWatchedDirectoriesRecursive);
|
||||
verifyWatchesOfProject(host, withTsserver ? expectedWatchedFiles().filter(f => f !== tests[1].path.toLowerCase()) : expectedWatchedFiles(), expectedWatchedDirectoriesRecursive);
|
||||
}
|
||||
|
||||
function verifyScenario(
|
||||
edit: (host: TsBuildWatchSystem, solutionBuilder: SolutionBuilder<EmitAndSemanticDiagnosticsBuilderProgram>) => void,
|
||||
expectedFilesAfterEdit: ReadonlyArray<string>
|
||||
expectedFilesAfterEdit: () => ReadonlyArray<string>
|
||||
) {
|
||||
it("with tsc-watch", () => {
|
||||
const { host, solutionBuilder, watch } = createSolutionAndWatchMode();
|
||||
@@ -708,7 +738,7 @@ let x: string = 10;`);
|
||||
|
||||
host.checkTimeoutQueueLengthAndRun(1);
|
||||
checkOutputErrorsIncremental(host, emptyArray);
|
||||
checkProgramActualFiles(watch(), expectedFilesAfterEdit);
|
||||
checkProgramActualFiles(watch(), expectedFilesAfterEdit());
|
||||
|
||||
});
|
||||
|
||||
@@ -718,7 +748,7 @@ let x: string = 10;`);
|
||||
edit(host, solutionBuilder);
|
||||
|
||||
host.checkTimeoutQueueLengthAndRun(2);
|
||||
checkProjectActualFiles(service, tests[0].path, [tests[0].path, ...expectedFilesAfterEdit]);
|
||||
checkProjectActualFiles(service, tests[0].path, [tests[0].path, ...expectedFilesAfterEdit()]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -729,7 +759,7 @@ let x: string = 10;`);
|
||||
verifyDependencies(watch, coreIndexDts, [coreIndexDts]);
|
||||
verifyDependencies(watch, coreAnotherModuleDts, [coreAnotherModuleDts]);
|
||||
verifyDependencies(watch, logicIndexDts, [logicIndexDts, coreAnotherModuleDts]);
|
||||
verifyDependencies(watch, tests[1].path, expectedProgramFiles.filter(f => f !== libFile.path));
|
||||
verifyDependencies(watch, tests[1].path, expectedProgramFiles().filter(f => f !== libFile.path));
|
||||
});
|
||||
|
||||
it("with tsserver", () => {
|
||||
@@ -769,7 +799,7 @@ export function gfoo() {
|
||||
}));
|
||||
solutionBuilder.invalidateProject(logic[0].path.toLowerCase() as ResolvedConfigFilePath, ConfigFileProgramReloadLevel.Full);
|
||||
solutionBuilder.buildNextInvalidatedProject();
|
||||
}, [tests[1].path, libFile.path, coreIndexDts, coreAnotherModuleDts, projectFilePath(SubProject.logic, "decls/index.d.ts")]);
|
||||
}, () => [tests[1].path, libFile.path, coreIndexDts, coreAnotherModuleDts, projectFilePath(SubProject.logic, "decls/index.d.ts")]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ts.tscWatch {
|
||||
};
|
||||
const files = [file1, libFile];
|
||||
const environmentVariables = createMap<string>();
|
||||
environmentVariables.set("TSC_WATCHFILE", "DynamicPriorityPolling");
|
||||
environmentVariables.set("TSC_WATCHFILE", TestFSWithWatch.Tsc_WatchFile.DynamicPolling);
|
||||
const host = createWatchedSystem(files, { environmentVariables });
|
||||
const watch = createWatchOfFilesAndCompilerOptions([file1.path], host);
|
||||
|
||||
|
||||
@@ -866,12 +866,12 @@ namespace ts.projectSystem {
|
||||
const projectService = createProjectService(host);
|
||||
projectService.openClientFile(file1.path);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
// Since there is no file open from configFile it would be closed
|
||||
checkNumberOfConfiguredProjects(projectService, 0);
|
||||
checkNumberOfInferredProjects(projectService, 1);
|
||||
|
||||
// Since file1 refers to config file as the default project, it needs to be kept alive
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1, configuredProjects: 1 });
|
||||
const inferredProject = projectService.inferredProjects[0];
|
||||
assert.isTrue(inferredProject.containsFile(<server.NormalizedPath>file1.path));
|
||||
assert.isFalse(projectService.configuredProjects.get(configFile.path)!.containsFile(<server.NormalizedPath>file1.path));
|
||||
});
|
||||
|
||||
it("should be able to handle @types if input file list is empty", () => {
|
||||
@@ -898,8 +898,8 @@ namespace ts.projectSystem {
|
||||
const projectService = createProjectService(host);
|
||||
|
||||
projectService.openClientFile(f.path);
|
||||
// Since no file from the configured project is open, it would be closed immediately
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
|
||||
// Since f refers to config file as the default project, it needs to be kept alive
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 1, inferredProjects: 1 });
|
||||
});
|
||||
|
||||
it("should tolerate invalid include files that start in subDirectory", () => {
|
||||
@@ -924,8 +924,8 @@ namespace ts.projectSystem {
|
||||
const projectService = createProjectService(host);
|
||||
|
||||
projectService.openClientFile(f.path);
|
||||
// Since no file from the configured project is open, it would be closed immediately
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
|
||||
// Since f refers to config file as the default project, it needs to be kept alive
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 1, inferredProjects: 1 });
|
||||
});
|
||||
|
||||
it("Changed module resolution reflected when specifying files list", () => {
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
namespace ts.projectSystem {
|
||||
interface DocumentSpanFromSubstring {
|
||||
file: File;
|
||||
text: string;
|
||||
options?: SpanFromSubstringOptions;
|
||||
contextText?: string;
|
||||
contextOptions?: SpanFromSubstringOptions;
|
||||
}
|
||||
function documentSpanFromSubstring({ file, text, contextText, options, contextOptions }: DocumentSpanFromSubstring): DocumentSpan {
|
||||
const contextSpan = contextText !== undefined ? documentSpanFromSubstring({ file, text: contextText, options: contextOptions }) : undefined;
|
||||
return {
|
||||
@@ -19,19 +12,6 @@ namespace ts.projectSystem {
|
||||
return documentSpanFromSubstring(input);
|
||||
}
|
||||
|
||||
interface MakeReferenceItem extends DocumentSpanFromSubstring {
|
||||
isDefinition: boolean;
|
||||
lineText: string;
|
||||
}
|
||||
function makeReferenceItem({ isDefinition, lineText, ...rest }: MakeReferenceItem): protocol.ReferencesResponseItem {
|
||||
return {
|
||||
...protocolFileSpanWithContextFromSubstring(rest),
|
||||
isDefinition,
|
||||
isWriteAccess: isDefinition,
|
||||
lineText,
|
||||
};
|
||||
}
|
||||
|
||||
interface MakeReferenceEntry extends DocumentSpanFromSubstring {
|
||||
isDefinition: boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
namespace ts.projectSystem {
|
||||
describe("unittests:: tsserver:: getExportReferences", () => {
|
||||
const exportVariable = "export const value = 0;";
|
||||
const exportArrayDestructured = "export const [valueA, valueB] = [0, 1];";
|
||||
const exportObjectDestructured = "export const { valueC, valueD: renamedD } = { valueC: 0, valueD: 1 };";
|
||||
const exportNestedObject = "export const { nest: [valueE, { valueF }] } = { nest: [0, { valueF: 1 }] };";
|
||||
|
||||
const mainTs: File = {
|
||||
path: "/main.ts",
|
||||
content: 'import { value, valueA, valueB, valueC, renamedD, valueE, valueF } from "./mod";',
|
||||
};
|
||||
const modTs: File = {
|
||||
path: "/mod.ts",
|
||||
content: `${exportVariable}
|
||||
${exportArrayDestructured}
|
||||
${exportObjectDestructured}
|
||||
${exportNestedObject}
|
||||
`,
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: "/tsconfig.json",
|
||||
content: "{}",
|
||||
};
|
||||
|
||||
function makeSampleSession() {
|
||||
const host = createServerHost([mainTs, modTs, tsconfig]);
|
||||
const session = createSession(host);
|
||||
openFilesForSession([mainTs, modTs], session);
|
||||
return session;
|
||||
}
|
||||
|
||||
const referenceMainTs = (mainTs: File, text: string): protocol.ReferencesResponseItem =>
|
||||
makeReferenceItem({
|
||||
file: mainTs,
|
||||
isDefinition: true,
|
||||
lineText: mainTs.content,
|
||||
contextText: mainTs.content,
|
||||
text,
|
||||
});
|
||||
|
||||
const referenceModTs = (
|
||||
texts: { text: string; lineText: string; contextText?: string },
|
||||
override: Partial<MakeReferenceItem> = {},
|
||||
): protocol.ReferencesResponseItem =>
|
||||
makeReferenceItem({
|
||||
file: modTs,
|
||||
isDefinition: true,
|
||||
...texts,
|
||||
...override,
|
||||
});
|
||||
|
||||
it("should get const variable declaration references", () => {
|
||||
const session = makeSampleSession();
|
||||
|
||||
const response = executeSessionRequest<protocol.ReferencesRequest, protocol.ReferencesResponse>(
|
||||
session,
|
||||
protocol.CommandTypes.References,
|
||||
protocolFileLocationFromSubstring(modTs, "value"),
|
||||
);
|
||||
|
||||
const expectResponse = {
|
||||
refs: [
|
||||
referenceModTs({ text: "value", lineText: exportVariable, contextText: exportVariable }),
|
||||
referenceMainTs(mainTs, "value"),
|
||||
],
|
||||
symbolDisplayString: "const value: 0",
|
||||
symbolName: "value",
|
||||
symbolStartOffset: protocolLocationFromSubstring(modTs.content, "value").offset,
|
||||
};
|
||||
|
||||
assert.deepEqual(response, expectResponse);
|
||||
});
|
||||
|
||||
it("should get array destructuring declaration references", () => {
|
||||
const session = makeSampleSession();
|
||||
const response = executeSessionRequest<protocol.ReferencesRequest, protocol.ReferencesResponse>(
|
||||
session,
|
||||
protocol.CommandTypes.References,
|
||||
protocolFileLocationFromSubstring(modTs, "valueA"),
|
||||
);
|
||||
|
||||
const expectResponse = {
|
||||
refs: [
|
||||
referenceModTs({
|
||||
text: "valueA",
|
||||
lineText: exportArrayDestructured,
|
||||
contextText: exportArrayDestructured,
|
||||
}),
|
||||
referenceMainTs(mainTs, "valueA"),
|
||||
],
|
||||
symbolDisplayString: "const valueA: number",
|
||||
symbolName: "valueA",
|
||||
symbolStartOffset: protocolLocationFromSubstring(modTs.content, "valueA").offset,
|
||||
};
|
||||
|
||||
assert.deepEqual(response, expectResponse);
|
||||
});
|
||||
|
||||
it("should get object destructuring declaration references", () => {
|
||||
const session = makeSampleSession();
|
||||
const response = executeSessionRequest<protocol.ReferencesRequest, protocol.ReferencesResponse>(
|
||||
session,
|
||||
protocol.CommandTypes.References,
|
||||
protocolFileLocationFromSubstring(modTs, "valueC"),
|
||||
);
|
||||
const expectResponse = {
|
||||
refs: [
|
||||
referenceModTs({
|
||||
text: "valueC",
|
||||
lineText: exportObjectDestructured,
|
||||
contextText: exportObjectDestructured,
|
||||
}),
|
||||
referenceMainTs(mainTs, "valueC"),
|
||||
referenceModTs(
|
||||
{ text: "valueC", lineText: exportObjectDestructured, contextText: "valueC: 0" },
|
||||
{ options: { index: 1 } },
|
||||
),
|
||||
],
|
||||
symbolDisplayString: "const valueC: number",
|
||||
symbolName: "valueC",
|
||||
symbolStartOffset: protocolLocationFromSubstring(modTs.content, "valueC").offset,
|
||||
};
|
||||
|
||||
assert.deepEqual(response, expectResponse);
|
||||
});
|
||||
|
||||
it("should get object declaration references that renames destructured property", () => {
|
||||
const session = makeSampleSession();
|
||||
const response = executeSessionRequest<protocol.ReferencesRequest, protocol.ReferencesResponse>(
|
||||
session,
|
||||
protocol.CommandTypes.References,
|
||||
protocolFileLocationFromSubstring(modTs, "renamedD"),
|
||||
);
|
||||
|
||||
const expectResponse = {
|
||||
refs: [
|
||||
referenceModTs({
|
||||
text: "renamedD",
|
||||
lineText: exportObjectDestructured,
|
||||
contextText: exportObjectDestructured,
|
||||
}),
|
||||
referenceMainTs(mainTs, "renamedD"),
|
||||
],
|
||||
symbolDisplayString: "const renamedD: number",
|
||||
symbolName: "renamedD",
|
||||
symbolStartOffset: protocolLocationFromSubstring(modTs.content, "renamedD").offset,
|
||||
};
|
||||
|
||||
assert.deepEqual(response, expectResponse);
|
||||
});
|
||||
|
||||
it("should get nested object declaration references", () => {
|
||||
const session = makeSampleSession();
|
||||
const response = executeSessionRequest<protocol.ReferencesRequest, protocol.ReferencesResponse>(
|
||||
session,
|
||||
protocol.CommandTypes.References,
|
||||
protocolFileLocationFromSubstring(modTs, "valueF"),
|
||||
);
|
||||
|
||||
const expectResponse = {
|
||||
refs: [
|
||||
referenceModTs({
|
||||
text: "valueF",
|
||||
lineText: exportNestedObject,
|
||||
contextText: exportNestedObject,
|
||||
}),
|
||||
referenceMainTs(mainTs, "valueF"),
|
||||
referenceModTs(
|
||||
{
|
||||
text: "valueF",
|
||||
lineText: exportNestedObject,
|
||||
contextText: "valueF: 1",
|
||||
},
|
||||
{ options: { index: 1 } },
|
||||
),
|
||||
],
|
||||
symbolDisplayString: "const valueF: number",
|
||||
symbolName: "valueF",
|
||||
symbolStartOffset: protocolLocationFromSubstring(modTs.content, "valueF").offset,
|
||||
};
|
||||
|
||||
assert.deepEqual(response, expectResponse);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -519,6 +519,8 @@ namespace ts.projectSystem {
|
||||
file: File;
|
||||
text: string;
|
||||
options?: SpanFromSubstringOptions;
|
||||
contextText?: string;
|
||||
contextOptions?: SpanFromSubstringOptions;
|
||||
}
|
||||
export function protocolFileSpanFromSubstring({ file, text, options }: DocumentSpanFromSubstring): protocol.FileSpan {
|
||||
return { file: file.path, ...protocolTextSpanFromSubstring(file.content, text, options) };
|
||||
@@ -727,4 +729,18 @@ namespace ts.projectSystem {
|
||||
assert.strictEqual(outputs.length, index + 1, JSON.stringify(outputs));
|
||||
}
|
||||
}
|
||||
|
||||
export interface MakeReferenceItem extends DocumentSpanFromSubstring {
|
||||
isDefinition: boolean;
|
||||
lineText: string;
|
||||
}
|
||||
|
||||
export function makeReferenceItem({ isDefinition, lineText, ...rest }: MakeReferenceItem): protocol.ReferencesResponseItem {
|
||||
return {
|
||||
...protocolFileSpanWithContextFromSubstring(rest),
|
||||
isDefinition,
|
||||
isWriteAccess: isDefinition,
|
||||
lineText,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -345,5 +345,92 @@ namespace ts.projectSystem {
|
||||
it("inferred projects per project root with case insensitive system", () => {
|
||||
verifyProjectRootWithCaseSensitivity(/*useCaseSensitiveFileNames*/ false);
|
||||
});
|
||||
|
||||
it("should still retain configured project created while opening the file", () => {
|
||||
const projectRoot = "/user/username/projects/project";
|
||||
const appFile: File = {
|
||||
path: `${projectRoot}/app.ts`,
|
||||
content: `const app = 20;`
|
||||
};
|
||||
const config: File = {
|
||||
path: `${projectRoot}/tsconfig.json`,
|
||||
content: "{}"
|
||||
};
|
||||
const jsFile1: File = {
|
||||
path: `${projectRoot}/jsFile1.js`,
|
||||
content: `const jsFile1 = 10;`
|
||||
};
|
||||
const jsFile2: File = {
|
||||
path: `${projectRoot}/jsFile2.js`,
|
||||
content: `const jsFile2 = 10;`
|
||||
};
|
||||
const host = createServerHost([appFile, libFile, config, jsFile1, jsFile2]);
|
||||
const projectService = createProjectService(host);
|
||||
const originalSet = projectService.configuredProjects.set;
|
||||
const originalDelete = projectService.configuredProjects.delete;
|
||||
const configuredCreated = createMap<true>();
|
||||
const configuredRemoved = createMap<true>();
|
||||
projectService.configuredProjects.set = (key, value) => {
|
||||
assert.isFalse(configuredCreated.has(key));
|
||||
configuredCreated.set(key, true);
|
||||
return originalSet.call(projectService.configuredProjects, key, value);
|
||||
};
|
||||
projectService.configuredProjects.delete = key => {
|
||||
assert.isFalse(configuredRemoved.has(key));
|
||||
configuredRemoved.set(key, true);
|
||||
return originalDelete.call(projectService.configuredProjects, key);
|
||||
};
|
||||
|
||||
// Do not remove config project when opening jsFile that is not present as part of config project
|
||||
projectService.openClientFile(jsFile1.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1, configuredProjects: 1 });
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [jsFile1.path, libFile.path]);
|
||||
const project = projectService.configuredProjects.get(config.path)!;
|
||||
checkProjectActualFiles(project, [appFile.path, config.path, libFile.path]);
|
||||
checkConfiguredProjectCreatedAndNotDeleted();
|
||||
|
||||
// Do not remove config project when opening jsFile that is not present as part of config project
|
||||
projectService.closeClientFile(jsFile1.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1, configuredProjects: 1 });
|
||||
projectService.openClientFile(jsFile2.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1, configuredProjects: 1 });
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [jsFile2.path, libFile.path]);
|
||||
checkProjectActualFiles(project, [appFile.path, config.path, libFile.path]);
|
||||
checkConfiguredProjectNotCreatedAndNotDeleted();
|
||||
|
||||
// Do not remove config project when opening jsFile that is not present as part of config project
|
||||
projectService.openClientFile(jsFile1.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 2, configuredProjects: 1 });
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [jsFile2.path, libFile.path]);
|
||||
checkProjectActualFiles(projectService.inferredProjects[1], [jsFile1.path, libFile.path]);
|
||||
checkProjectActualFiles(project, [appFile.path, config.path, libFile.path]);
|
||||
checkConfiguredProjectNotCreatedAndNotDeleted();
|
||||
|
||||
// When opening file that doesnt fall back to the config file, we remove the config project
|
||||
projectService.openClientFile(libFile.path);
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 2 });
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [jsFile2.path, libFile.path]);
|
||||
checkProjectActualFiles(projectService.inferredProjects[1], [jsFile1.path, libFile.path]);
|
||||
checkConfiguredProjectNotCreatedButDeleted();
|
||||
|
||||
function checkConfiguredProjectCreatedAndNotDeleted() {
|
||||
assert.equal(configuredCreated.size, 1);
|
||||
assert.isTrue(configuredCreated.has(config.path));
|
||||
assert.equal(configuredRemoved.size, 0);
|
||||
configuredCreated.clear();
|
||||
}
|
||||
|
||||
function checkConfiguredProjectNotCreatedAndNotDeleted() {
|
||||
assert.equal(configuredCreated.size, 0);
|
||||
assert.equal(configuredRemoved.size, 0);
|
||||
}
|
||||
|
||||
function checkConfiguredProjectNotCreatedButDeleted() {
|
||||
assert.equal(configuredCreated.size, 0);
|
||||
assert.equal(configuredRemoved.size, 1);
|
||||
assert.isTrue(configuredRemoved.has(config.path));
|
||||
configuredRemoved.clear();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -634,13 +634,17 @@ namespace ts.projectSystem {
|
||||
path: "/a/main.js",
|
||||
content: "var y = 1"
|
||||
};
|
||||
const f3 = {
|
||||
path: "/main.js",
|
||||
content: "var y = 1"
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { allowJs: true }
|
||||
})
|
||||
};
|
||||
const host = createServerHost([f1, f2, config]);
|
||||
const host = createServerHost([f1, f2, f3, config]);
|
||||
const projectService = createProjectService(host);
|
||||
projectService.setHostConfiguration({
|
||||
extraFileExtensions: [
|
||||
@@ -652,13 +656,19 @@ namespace ts.projectSystem {
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 1 });
|
||||
checkProjectActualFiles(configuredProjectAt(projectService, 0), [f1.path, config.path]);
|
||||
|
||||
// Should close configured project with next file open
|
||||
// Since f2 refers to config file as the default project, it needs to be kept alive
|
||||
projectService.closeClientFile(f1.path);
|
||||
|
||||
projectService.openClientFile(f2.path);
|
||||
projectService.checkNumberOfProjects({ inferredProjects: 1, configuredProjects: 1 });
|
||||
assert.isDefined(projectService.configuredProjects.get(config.path));
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [f2.path]);
|
||||
|
||||
// Should close configured project with next file open
|
||||
projectService.closeClientFile(f2.path);
|
||||
projectService.openClientFile(f3.path);
|
||||
projectService.checkNumberOfProjects({ inferredProjects: 1 });
|
||||
assert.isUndefined(projectService.configuredProjects.get(config.path));
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [f2.path]);
|
||||
checkProjectActualFiles(projectService.inferredProjects[0], [f3.path]);
|
||||
});
|
||||
|
||||
it("tsconfig script block support", () => {
|
||||
|
||||
Reference in new issue
Block a user