@@ -25,7 +25,6 @@ import {
25
25
isComputedPropertyName ,
26
26
isIdentifier ,
27
27
memoize ,
28
- ObjectLiteralElementLike ,
29
28
PrivateIdentifier ,
30
29
ScriptTarget ,
31
30
setEmitFlags ,
@@ -251,65 +250,165 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel
251
250
] ) ;
252
251
}
253
252
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
+ // }
305
402
306
403
function createESDecorateClassElementContextObject ( contextIn : ESDecorateClassElementContext ) {
307
404
return factory . createObjectLiteralExpression ( [
308
405
factory . createPropertyAssignment ( factory . createIdentifier ( "kind" ) , factory . createStringLiteral ( contextIn . kind ) ) ,
309
406
factory . createPropertyAssignment ( factory . createIdentifier ( "name" ) , contextIn . name . computed ? contextIn . name . name : factory . createStringLiteralFromNode ( contextIn . name . name ) ) ,
310
407
factory . createPropertyAssignment ( factory . createIdentifier ( "static" ) , contextIn . static ? factory . createTrue ( ) : factory . createFalse ( ) ) ,
311
408
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))
313
412
] ) ;
314
413
}
315
414
0 commit comments