Skip to content

Commit 086e2c7

Browse files
committed
Retarget to es6 and fix the resulting bugs
1 parent 345777e commit 086e2c7

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

src/compiler/core.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,17 @@ namespace ts {
13861386
return keys;
13871387
}
13881388

1389+
export function getAllKeys(obj: object): string[] {
1390+
const result: string[] = [];
1391+
do {
1392+
const names = Object.getOwnPropertyNames(obj);
1393+
for (const name of names) {
1394+
pushIfUnique(result, name);
1395+
}
1396+
} while (obj = Object.getPrototypeOf(obj));
1397+
return result;
1398+
}
1399+
13891400
export function getOwnValues<T>(sparseArray: T[]): T[] {
13901401
const values: T[] = [];
13911402
for (const key in sparseArray) {

src/compiler/program.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,10 @@ namespace ts {
815815
let mapFromFileToProjectReferenceRedirects: Map<Path> | undefined;
816816

817817
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
818-
const structuralIsReused = tryReuseStructureFromOldProgram();
818+
// We set `structuralIsReused` to `undefined` because `tryReuseStructureFromOldProgram` calls `tryReuseStructureFromOldProgram` which checks
819+
// `structuralIsReused`, which would be a TDZ violation if it was not set in advance to `undefined`.
820+
let structuralIsReused: StructureIsReused | undefined;
821+
structuralIsReused = tryReuseStructureFromOldProgram();
819822
if (structuralIsReused !== StructureIsReused.Completely) {
820823
processingDefaultLibFiles = [];
821824
processingOtherFiles = [];

src/compiler/transformers/declarations.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace ts {
8383
let currentSourceFile: SourceFile;
8484
let refs: Map<SourceFile>;
8585
let libs: Map<boolean>;
86+
let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass
8687
const resolver = context.getEmitResolver();
8788
const options = context.getCompilerOptions();
8889
const newLine = getNewLineCharacter(options);
@@ -279,7 +280,7 @@ namespace ts {
279280
const statements = visitNodes(node.statements, visitDeclarationStatements);
280281
let combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements);
281282
refs.forEach(referenceVisitor);
282-
const emittedImports = filter(combinedStatements, isAnyImportSyntax);
283+
emittedImports = filter(combinedStatements, isAnyImportSyntax);
283284
if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) {
284285
combinedStatements = setTextRange(createNodeArray([...combinedStatements, createEmptyExports()]), combinedStatements);
285286
}
@@ -736,6 +737,12 @@ namespace ts {
736737
}
737738
const oldDiag = getSymbolAccessibilityDiagnostic;
738739

740+
// Setup diagnostic-related flags before first potential `cleanup` call, otherwise
741+
// We'd see a TDZ violation ar runtime
742+
const canProdiceDiagnostic = canProduceDiagnostics(input);
743+
const oldWithinObjectLiteralType = suppressNewDiagnosticContexts;
744+
let shouldEnterSuppressNewDiagnosticsContextContext = ((input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration);
745+
739746
// Emit methods which are private as properties with no type information
740747
if (isMethodDeclaration(input) || isMethodSignature(input)) {
741748
if (hasModifier(input, ModifierFlags.Private)) {
@@ -744,7 +751,6 @@ namespace ts {
744751
}
745752
}
746753

747-
const canProdiceDiagnostic = canProduceDiagnostics(input);
748754
if (canProdiceDiagnostic && !suppressNewDiagnosticContexts) {
749755
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input as DeclarationDiagnosticProducing);
750756
}
@@ -753,8 +759,6 @@ namespace ts {
753759
checkEntityNameVisibility(input.exprName, enclosingDeclaration);
754760
}
755761

756-
const oldWithinObjectLiteralType = suppressNewDiagnosticContexts;
757-
let shouldEnterSuppressNewDiagnosticsContextContext = ((input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration);
758762
if (shouldEnterSuppressNewDiagnosticsContextContext) {
759763
// 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.
760764
suppressNewDiagnosticContexts = true;

src/harness/fourslash.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ namespace FourSlash {
344344
"getDocumentHighlights",
345345
];
346346
const proxy = {} as ts.LanguageService;
347-
for (const k in ls) {
347+
const keys = ts.getAllKeys(ls);
348+
for (const k of keys) {
348349
const key = k as keyof typeof ls;
349350
if (cacheableMembers.indexOf(key) === -1) {
350351
proxy[key] = (...args: any[]) => (ls[key] as Function)(...args);

src/tsconfig-base.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"pretty": true,
44
"lib": ["es2015.iterable", "es5"],
5-
"target": "es5",
5+
"moduleResolution": "node",
6+
"target": "es6",
67
"rootDir": ".",
78

89
"declaration": true,

0 commit comments

Comments
 (0)