Skip to content

Commit 673073c

Browse files
committed
Temporarily disable 'context.access'
1 parent 02e93fd commit 673073c

File tree

101 files changed

+630
-609
lines changed

Some content is hidden

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

101 files changed

+630
-609
lines changed

src/compiler/factory/emitHelpers.ts

+152-53
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
isComputedPropertyName,
2626
isIdentifier,
2727
memoize,
28-
ObjectLiteralElementLike,
2928
PrivateIdentifier,
3029
ScriptTarget,
3130
setEmitFlags,
@@ -251,65 +250,165 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel
251250
]);
252251
}
253252

254-
function createESDecorateClassElementAccessGetMethod(elementName: ESDecorateName) {
255-
const accessor = elementName.computed ?
256-
factory.createElementAccessExpression(factory.createThis(), elementName.name) :
257-
factory.createPropertyAccessExpression(factory.createThis(), elementName.name);
258-
259-
return factory.createMethodDeclaration(
260-
/*modifiers*/ undefined,
261-
/*asteriskToken*/ undefined,
262-
"get",
263-
/*questionToken*/ undefined,
264-
/*typeParameters*/ undefined,
265-
[],
266-
/*type*/ undefined,
267-
factory.createBlock([factory.createReturnStatement(accessor)])
268-
);
269-
}
270-
271-
function createESDecorateClassElementAccessSetMethod(elementName: ESDecorateName) {
272-
const accessor = elementName.computed ?
273-
factory.createElementAccessExpression(factory.createThis(), elementName.name) :
274-
factory.createPropertyAccessExpression(factory.createThis(), elementName.name);
275-
276-
return factory.createMethodDeclaration(
277-
/*modifiers*/ undefined,
278-
/*asteriskToken*/ undefined,
279-
"set",
280-
/*questionToken*/ undefined,
281-
/*typeParameters*/ undefined,
282-
[factory.createParameterDeclaration(
283-
/*modifiers*/ undefined,
284-
/*dotDotDotToken*/ undefined,
285-
factory.createIdentifier("value")
286-
)],
287-
/*type*/ undefined,
288-
factory.createBlock([
289-
factory.createExpressionStatement(
290-
factory.createAssignment(
291-
accessor,
292-
factory.createIdentifier("value")
293-
)
294-
)
295-
])
296-
);
297-
}
298-
299-
function createESDecorateClassElementAccessObject(name: ESDecorateName, access: ESDecorateClassElementAccess) {
300-
const properties: ObjectLiteralElementLike[] = [];
301-
if (access.get) properties.push(createESDecorateClassElementAccessGetMethod(name));
302-
if (access.set) properties.push(createESDecorateClassElementAccessSetMethod(name));
303-
return factory.createObjectLiteralExpression(properties);
304-
}
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+
// }
305402

306403
function createESDecorateClassElementContextObject(contextIn: ESDecorateClassElementContext) {
307404
return factory.createObjectLiteralExpression([
308405
factory.createPropertyAssignment(factory.createIdentifier("kind"), factory.createStringLiteral(contextIn.kind)),
309406
factory.createPropertyAssignment(factory.createIdentifier("name"), contextIn.name.computed ? contextIn.name.name : factory.createStringLiteralFromNode(contextIn.name.name)),
310407
factory.createPropertyAssignment(factory.createIdentifier("static"), contextIn.static ? factory.createTrue() : factory.createFalse()),
311408
factory.createPropertyAssignment(factory.createIdentifier("private"), contextIn.private ? factory.createTrue() : factory.createFalse()),
312-
factory.createPropertyAssignment(factory.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access))
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))
313412
]);
314413
}
315414

src/compiler/transformers/classFields.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1052,16 +1052,14 @@ export function transformClassFields(context: TransformationContext): (x: Source
10521052
return undefined;
10531053
}
10541054

1055-
factory.updatePropertyDeclaration(
1055+
return factory.updatePropertyDeclaration(
10561056
node,
10571057
visitNodes(node.modifiers, modifierVisitor, isModifier),
10581058
visitNode(node.name, propertyNameVisitor, isPropertyName),
10591059
/*questionOrExclamationToken*/ undefined,
10601060
/*type*/ undefined,
10611061
visitNode(node.initializer, visitor, isExpression)
1062-
)
1063-
1064-
return visitEachChild(node, classElementVisitor, context);
1062+
);
10651063
}
10661064

10671065
function transformFieldInitializer(node: PropertyDeclaration) {

0 commit comments

Comments
 (0)