Skip to content

Commit 586a2e5

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/TypeScript into fix(52604)
2 parents 4f88134 + 38b951e commit 586a2e5

File tree

338 files changed

+12770
-1962
lines changed

Some content is hidden

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

338 files changed

+12770
-1962
lines changed

package-lock.json

Lines changed: 314 additions & 314 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
generateDjb2Hash,
4646
getDirectoryPath,
4747
getEmitDeclarations,
48+
getIsolatedModules,
4849
getNormalizedAbsolutePath,
4950
getOptionsNameMap,
5051
getOwnKeys,
@@ -763,7 +764,7 @@ function handleDtsMayChangeOfReferencingExportOfAffectedFile(
763764

764765
// Since isolated modules dont change js files, files affected by change in signature is itself
765766
// But we need to cleanup semantic diagnostics and queue dts emit for affected files
766-
if (state.compilerOptions.isolatedModules) {
767+
if (getIsolatedModules(state.compilerOptions)) {
767768
const seenFileNamesMap = new Map<Path, true>();
768769
seenFileNamesMap.set(affectedFile.resolvedPath, true);
769770
const queue = BuilderState.getReferencedByPaths(state, affectedFile.resolvedPath);

src/compiler/builderState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ExportedModulesFromDeclarationEmit,
1010
GetCanonicalFileName,
1111
getDirectoryPath,
12+
getIsolatedModules,
1213
getSourceFileOfNode,
1314
HostForComputeHash,
1415
isDeclarationFileName,
@@ -635,7 +636,7 @@ export namespace BuilderState {
635636
}
636637

637638
const compilerOptions = programOfThisState.getCompilerOptions();
638-
if (compilerOptions && (compilerOptions.isolatedModules || outFile(compilerOptions))) {
639+
if (compilerOptions && (getIsolatedModules(compilerOptions) || outFile(compilerOptions))) {
639640
return [sourceFileWithUpdatedShape];
640641
}
641642

src/compiler/checker.ts

Lines changed: 368 additions & 140 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,10 @@
15891589
"category": "Error",
15901590
"code": 1485
15911591
},
1592+
"Decorator used before 'export' here.": {
1593+
"category": "Error",
1594+
"code": 1486
1595+
},
15921596

15931597
"The types of '{0}' are incompatible between these types.": {
15941598
"category": "Error",
@@ -6560,7 +6564,7 @@
65606564
"category": "Error",
65616565
"code": 8037
65626566
},
6563-
"Decorators must come after 'export' or 'export default' in JavaScript files.": {
6567+
"Decorators may not appear after 'export' or 'export default' if they also appear before 'export'.": {
65646568
"category": "Error",
65656569
"code": 8038
65666570
},

src/compiler/factory/emitHelpers.ts

Lines changed: 93 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
isComputedPropertyName,
2626
isIdentifier,
2727
memoize,
28+
ObjectLiteralElementLike,
2829
PrivateIdentifier,
2930
ScriptTarget,
3031
setEmitFlags,
@@ -250,165 +251,105 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel
250251
]);
251252
}
252253

253-
// Per https://github.com/tc39/proposal-decorators/issues/494, we may need to change the emit for the `access` object
254-
// so that it does not need to be used via `.call`. The following two sections represent the options presented in
255-
// tc39/proposal-decorators#494
256-
//
257-
// === Current approach (`access.get.call(obj)`, `access.set.call(obj, value)`) ===
258-
//
259-
// function createESDecorateClassElementAccessGetMethod(elementName: ESDecorateName) {
260-
// const accessor = elementName.computed ?
261-
// factory.createElementAccessExpression(factory.createThis(), elementName.name) :
262-
// factory.createPropertyAccessExpression(factory.createThis(), elementName.name);
263-
//
264-
// return factory.createMethodDeclaration(
265-
// /*modifiers*/ undefined,
266-
// /*asteriskToken*/ undefined,
267-
// "get",
268-
// /*questionToken*/ undefined,
269-
// /*typeParameters*/ undefined,
270-
// [],
271-
// /*type*/ undefined,
272-
// factory.createBlock([factory.createReturnStatement(accessor)])
273-
// );
274-
// }
275-
//
276-
// function createESDecorateClassElementAccessSetMethod(elementName: ESDecorateName) {
277-
// const accessor = elementName.computed ?
278-
// factory.createElementAccessExpression(factory.createThis(), elementName.name) :
279-
// factory.createPropertyAccessExpression(factory.createThis(), elementName.name);
280-
//
281-
// return factory.createMethodDeclaration(
282-
// /*modifiers*/ undefined,
283-
// /*asteriskToken*/ undefined,
284-
// "set",
285-
// /*questionToken*/ undefined,
286-
// /*typeParameters*/ undefined,
287-
// [factory.createParameterDeclaration(
288-
// /*modifiers*/ undefined,
289-
// /*dotDotDotToken*/ undefined,
290-
// factory.createIdentifier("value")
291-
// )],
292-
// /*type*/ undefined,
293-
// factory.createBlock([
294-
// factory.createExpressionStatement(
295-
// factory.createAssignment(
296-
// accessor,
297-
// factory.createIdentifier("value")
298-
// )
299-
// )
300-
// ])
301-
// );
302-
// }
303-
//
304-
// function createESDecorateClassElementAccessObject(name: ESDecorateName, access: ESDecorateClassElementAccess) {
305-
// const properties: ObjectLiteralElementLike[] = [];
306-
// if (access.get) properties.push(createESDecorateClassElementAccessGetMethod(name));
307-
// if (access.set) properties.push(createESDecorateClassElementAccessSetMethod(name));
308-
// return factory.createObjectLiteralExpression(properties);
309-
// }
310-
//
311-
// === Suggested approach (`access.get(obj)`, `access.set(obj, value)`, `access.has(obj)`) ===
312-
//
313-
// function createESDecorateClassElementAccessGetMethod(elementName: ESDecorateName) {
314-
// const accessor = elementName.computed ?
315-
// factory.createElementAccessExpression(factory.createIdentifier("obj"), elementName.name) :
316-
// factory.createPropertyAccessExpression(factory.createIdentifier("obj"), elementName.name);
317-
//
318-
// return factory.createMethodDeclaration(
319-
// /*modifiers*/ undefined,
320-
// /*asteriskToken*/ undefined,
321-
// "get",
322-
// /*questionToken*/ undefined,
323-
// /*typeParameters*/ undefined,
324-
// [factory.createParameterDeclaration(
325-
// /*modifiers*/ undefined,
326-
// /*dotDotDotToken*/ undefined,
327-
// factory.createIdentifier("obj")
328-
// )],
329-
// /*type*/ undefined,
330-
// factory.createBlock([factory.createReturnStatement(accessor)])
331-
// );
332-
// }
333-
//
334-
// function createESDecorateClassElementAccessSetMethod(elementName: ESDecorateName) {
335-
// const accessor = elementName.computed ?
336-
// factory.createElementAccessExpression(factory.createIdentifier("obj"), elementName.name) :
337-
// factory.createPropertyAccessExpression(factory.createIdentifier("obj"), elementName.name);
338-
//
339-
// return factory.createMethodDeclaration(
340-
// /*modifiers*/ undefined,
341-
// /*asteriskToken*/ undefined,
342-
// "set",
343-
// /*questionToken*/ undefined,
344-
// /*typeParameters*/ undefined,
345-
// [factory.createParameterDeclaration(
346-
// /*modifiers*/ undefined,
347-
// /*dotDotDotToken*/ undefined,
348-
// factory.createIdentifier("obj")
349-
// ),
350-
// factory.createParameterDeclaration(
351-
// /*modifiers*/ undefined,
352-
// /*dotDotDotToken*/ undefined,
353-
// factory.createIdentifier("value")
354-
// )],
355-
// /*type*/ undefined,
356-
// factory.createBlock([
357-
// factory.createExpressionStatement(
358-
// factory.createAssignment(
359-
// accessor,
360-
// factory.createIdentifier("value")
361-
// )
362-
// )
363-
// ])
364-
// );
365-
// }
366-
//
367-
// function createESDecorateClassElementAccessHasMethod(elementName: ESDecorateName) {
368-
// const propertyName =
369-
// elementName.computed ? elementName.name :
370-
// isIdentifier(elementName.name) ? factory.createStringLiteralFromNode(elementName.name) :
371-
// elementName.name;
372-
//
373-
// return factory.createMethodDeclaration(
374-
// /*modifiers*/ undefined,
375-
// /*asteriskToken*/ undefined,
376-
// "has",
377-
// /*questionToken*/ undefined,
378-
// /*typeParameters*/ undefined,
379-
// [factory.createParameterDeclaration(
380-
// /*modifiers*/ undefined,
381-
// /*dotDotDotToken*/ undefined,
382-
// factory.createIdentifier("obj")
383-
// )],
384-
// /*type*/ undefined,
385-
// factory.createBlock([factory.createReturnStatement(
386-
// factory.createBinaryExpression(
387-
// propertyName,
388-
// SyntaxKind.InKeyword,
389-
// factory.createIdentifier("obj")
390-
// )
391-
// )])
392-
// );
393-
// }
394-
//
395-
// function createESDecorateClassElementAccessObject(name: ESDecorateName, access: ESDecorateClassElementAccess) {
396-
// const properties: ObjectLiteralElementLike[] = [];
397-
// if (access.get) properties.push(createESDecorateClassElementAccessGetMethod(name));
398-
// if (access.set) properties.push(createESDecorateClassElementAccessSetMethod(name));
399-
// property.push(createESDecorateClassElementAccessHasMethod(name));
400-
// return factory.createObjectLiteralExpression(properties);
401-
// }
254+
255+
function createESDecorateClassElementAccessGetMethod(elementName: ESDecorateName) {
256+
const accessor = elementName.computed ?
257+
factory.createElementAccessExpression(factory.createIdentifier("obj"), elementName.name) :
258+
factory.createPropertyAccessExpression(factory.createIdentifier("obj"), elementName.name);
259+
260+
return factory.createPropertyAssignment(
261+
"get",
262+
factory.createArrowFunction(
263+
/*modifiers*/ undefined,
264+
/*typeParameters*/ undefined,
265+
[factory.createParameterDeclaration(
266+
/*modifiers*/ undefined,
267+
/*dotDotDotToken*/ undefined,
268+
factory.createIdentifier("obj")
269+
)],
270+
/*type*/ undefined,
271+
/*equalsGreaterThanToken*/ undefined,
272+
accessor
273+
)
274+
);
275+
}
276+
277+
function createESDecorateClassElementAccessSetMethod(elementName: ESDecorateName) {
278+
const accessor = elementName.computed ?
279+
factory.createElementAccessExpression(factory.createIdentifier("obj"), elementName.name) :
280+
factory.createPropertyAccessExpression(factory.createIdentifier("obj"), elementName.name);
281+
282+
return factory.createPropertyAssignment(
283+
"set",
284+
factory.createArrowFunction(
285+
/*modifiers*/ undefined,
286+
/*typeParameters*/ undefined,
287+
[factory.createParameterDeclaration(
288+
/*modifiers*/ undefined,
289+
/*dotDotDotToken*/ undefined,
290+
factory.createIdentifier("obj")
291+
),
292+
factory.createParameterDeclaration(
293+
/*modifiers*/ undefined,
294+
/*dotDotDotToken*/ undefined,
295+
factory.createIdentifier("value")
296+
)],
297+
/*type*/ undefined,
298+
/*equalsGreaterThanToken*/ undefined,
299+
factory.createBlock([
300+
factory.createExpressionStatement(
301+
factory.createAssignment(
302+
accessor,
303+
factory.createIdentifier("value")
304+
)
305+
)
306+
])
307+
)
308+
);
309+
}
310+
311+
function createESDecorateClassElementAccessHasMethod(elementName: ESDecorateName) {
312+
const propertyName =
313+
elementName.computed ? elementName.name :
314+
isIdentifier(elementName.name) ? factory.createStringLiteralFromNode(elementName.name) :
315+
elementName.name;
316+
317+
return factory.createPropertyAssignment(
318+
"has",
319+
factory.createArrowFunction(
320+
/*modifiers*/ undefined,
321+
/*typeParameters*/ undefined,
322+
[factory.createParameterDeclaration(
323+
/*modifiers*/ undefined,
324+
/*dotDotDotToken*/ undefined,
325+
factory.createIdentifier("obj")
326+
)],
327+
/*type*/ undefined,
328+
/*equalsGreaterThanToken*/ undefined,
329+
factory.createBinaryExpression(
330+
propertyName,
331+
SyntaxKind.InKeyword,
332+
factory.createIdentifier("obj")
333+
)
334+
)
335+
);
336+
}
337+
338+
function createESDecorateClassElementAccessObject(name: ESDecorateName, access: ESDecorateClassElementAccess) {
339+
const properties: ObjectLiteralElementLike[] = [];
340+
properties.push(createESDecorateClassElementAccessHasMethod(name));
341+
if (access.get) properties.push(createESDecorateClassElementAccessGetMethod(name));
342+
if (access.set) properties.push(createESDecorateClassElementAccessSetMethod(name));
343+
return factory.createObjectLiteralExpression(properties);
344+
}
402345

403346
function createESDecorateClassElementContextObject(contextIn: ESDecorateClassElementContext) {
404347
return factory.createObjectLiteralExpression([
405348
factory.createPropertyAssignment(factory.createIdentifier("kind"), factory.createStringLiteral(contextIn.kind)),
406349
factory.createPropertyAssignment(factory.createIdentifier("name"), contextIn.name.computed ? contextIn.name.name : factory.createStringLiteralFromNode(contextIn.name.name)),
407350
factory.createPropertyAssignment(factory.createIdentifier("static"), contextIn.static ? factory.createTrue() : factory.createFalse()),
408351
factory.createPropertyAssignment(factory.createIdentifier("private"), contextIn.private ? factory.createTrue() : factory.createFalse()),
409-
410-
// Disabled, pending resolution of https://github.com/tc39/proposal-decorators/issues/494
411-
// factory.createPropertyAssignment(factory.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access))
352+
factory.createPropertyAssignment(factory.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access))
412353
]);
413354
}
414355

src/compiler/factory/utilities.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,6 @@ export function canHaveIllegalModifiers(node: Node): node is HasIllegalModifiers
11511151
return kind === SyntaxKind.ClassStaticBlockDeclaration
11521152
|| kind === SyntaxKind.PropertyAssignment
11531153
|| kind === SyntaxKind.ShorthandPropertyAssignment
1154-
|| kind === SyntaxKind.FunctionType
11551154
|| kind === SyntaxKind.MissingDeclaration
11561155
|| kind === SyntaxKind.NamespaceExportDeclaration;
11571156
}

0 commit comments

Comments
 (0)