Skip to content

Commit 831a5b2

Browse files
committed
Temporarily disable 'context.access'
1 parent 02e93fd commit 831a5b2

File tree

100 files changed

+628
-605
lines changed

Some content is hidden

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

100 files changed

+628
-605
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/lib/decorators.d.ts

+64-59
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,17 @@ interface ClassMethodDecoratorContext<
7272
/** A value indicating whether the class member has a private name. */
7373
readonly private: boolean;
7474

75-
/** An object that can be used to access the current value of the class member at runtime. */
76-
readonly access: {
77-
/**
78-
* Gets the current value of the method from the provided receiver.
79-
*
80-
* @example
81-
* let fn = context.access.get.call(instance);
82-
*/
83-
get(this: This): Value;
84-
};
75+
// NOTE: Disabled, pending the outcome of https://github.com/tc39/proposal-decorators/issues/494
76+
// /** An object that can be used to access the current value of the class member at runtime. */
77+
// readonly access: {
78+
// /**
79+
// * Gets the current value of the method from the provided receiver.
80+
// *
81+
// * @example
82+
// * let fn = context.access.get.call(instance);
83+
// */
84+
// get(this: This): Value;
85+
// };
8586

8687
/**
8788
* Adds a callback to be invoked either before static initializers are run (when
@@ -132,16 +133,17 @@ interface ClassGetterDecoratorContext<
132133
/** A value indicating whether the class member has a private name. */
133134
readonly private: boolean;
134135

135-
/** An object that can be used to access the current value of the class member at runtime. */
136-
readonly access: {
137-
/**
138-
* Invokes the getter on the provided receiver.
139-
*
140-
* @example
141-
* let value = context.access.get.call(instance);
142-
*/
143-
get(this: This): Value;
144-
};
136+
// NOTE: Disabled, pending the outcome of https://github.com/tc39/proposal-decorators/issues/494
137+
// /** An object that can be used to access the current value of the class member at runtime. */
138+
// readonly access: {
139+
// /**
140+
// * Invokes the getter on the provided receiver.
141+
// *
142+
// * @example
143+
// * let value = context.access.get.call(instance);
144+
// */
145+
// get(this: This): Value;
146+
// };
145147

146148
/**
147149
* Adds a callback to be invoked either before static initializers are run (when
@@ -173,16 +175,17 @@ interface ClassSetterDecoratorContext<
173175
/** A value indicating whether the class member has a private name. */
174176
readonly private: boolean;
175177

178+
// NOTE: Disabled, pending the outcome of https://github.com/tc39/proposal-decorators/issues/494
176179
/** An object that can be used to access the current value of the class member at runtime. */
177-
readonly access: {
178-
/**
179-
* Invokes the setter on the provided receiver.
180-
*
181-
* @example
182-
* context.access.set.call(instance, value);
183-
*/
184-
set(this: This, value: Value): void;
185-
};
180+
// readonly access: {
181+
// /**
182+
// * Invokes the setter on the provided receiver.
183+
// *
184+
// * @example
185+
// * context.access.set.call(instance, value);
186+
// */
187+
// set(this: This, value: Value): void;
188+
// };
186189

187190
/**
188191
* Adds a callback to be invoked either before static initializers are run (when
@@ -214,24 +217,25 @@ interface ClassAccessorDecoratorContext<
214217
/** A value indicating whether the class member has a private name. */
215218
readonly private: boolean;
216219

217-
/** An object that can be used to access the current value of the class member at runtime. */
218-
readonly access: {
219-
/**
220-
* Invokes the getter on the provided receiver.
221-
*
222-
* @example
223-
* let value = context.access.get.call(instance);
224-
*/
225-
get(this: This): Value;
226-
227-
/**
228-
* Invokes the setter on the provided receiver.
229-
*
230-
* @example
231-
* context.access.set.call(instance, value);
232-
*/
233-
set(this: This, value: Value): void;
234-
};
220+
// NOTE: Disabled, pending the outcome of https://github.com/tc39/proposal-decorators/issues/494
221+
// /** An object that can be used to access the current value of the class member at runtime. */
222+
// readonly access: {
223+
// /**
224+
// * Invokes the getter on the provided receiver.
225+
// *
226+
// * @example
227+
// * let value = context.access.get.call(instance);
228+
// */
229+
// get(this: This): Value;
230+
231+
// /**
232+
// * Invokes the setter on the provided receiver.
233+
// *
234+
// * @example
235+
// * context.access.set.call(instance, value);
236+
// */
237+
// set(this: This, value: Value): void;
238+
// };
235239

236240
/**
237241
* Adds a callback to be invoked either before static initializers are run (when
@@ -310,18 +314,19 @@ interface ClassFieldDecoratorContext<
310314
/** A value indicating whether the class member has a private name. */
311315
readonly private: boolean;
312316

313-
/** An object that can be used to access the current value of the class member at runtime. */
314-
readonly access: {
315-
/**
316-
* Gets the value of the field on the provided receiver.
317-
*/
318-
get(this: This): Value;
319-
320-
/**
321-
* Sets the value of the field on the provided receiver.
322-
*/
323-
set(this: This, value: Value): void;
324-
};
317+
// NOTE: Disabled, pending the outcome of https://github.com/tc39/proposal-decorators/issues/494
318+
// /** An object that can be used to access the current value of the class member at runtime. */
319+
// readonly access: {
320+
// /**
321+
// * Gets the value of the field on the provided receiver.
322+
// */
323+
// get(this: This): Value;
324+
325+
// /**
326+
// * Sets the value of the field on the provided receiver.
327+
// */
328+
// set(this: This, value: Value): void;
329+
// };
325330

326331
/**
327332
* Adds a callback to be invoked either before static initializers are run (when

0 commit comments

Comments
 (0)