Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing has method on the access object in Decorator Contexts #22254

Open
nberlette opened this issue Feb 4, 2024 · 1 comment
Open

Missing has method on the access object in Decorator Contexts #22254

nberlette opened this issue Feb 4, 2024 · 1 comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling) upstream Changes in upstream are required to solve these issues

Comments

@nberlette
Copy link
Contributor

Version: Deno v1.40.3+0bfa0cc

After submitting issue #22253, which is also related to something missing in decorator context objects, I noticed that none of the context objects from the reproduction run seemed to have a has method in their access objects.

According to the proposal specification, only the get and set property should vary in their presence depending on the type of target being decorated. The has method is supposed to be present in the context of every decorator type (other than "class", obviously).

Here's a quick reproduction:

const example = (target, context) => {
  const { name, kind } = context;
  console.log(
    `name: "${name.toString()}"\nkind: ${
      context.kind
    }\n"access" in context => ${
      ("access" in context)
    }\n"has" in context.access => ${
      ("has" in context.access)
    }\n"get" in context.access => ${
      ("get" in context.access)
    }\n"set" in context.access => ${
      ("set" in context.access)
    }\n`,
  );
};

// quick, non-exhaustive demo with various target types
class Foo {
  @example someMethod() {/* ignore */}

  @example get someGetter() {
    return true;
  }

  @example set someSetter(_) {/* ignore */}

  @example accessor foobar = "bazbuzz";

  @example fieldOfBrokenDreams = "change me";
}

And the output of the above code is:

name: "someMethod"
kind: method
"access" in context => true
"has" in context.access => false
"get" in context.access => true
"set" in context.access => false

name: "someGetter"
kind: getter
"access" in context => true
"has" in context.access => false
"get" in context.access => true
"set" in context.access => false

name: "someSetter"
kind: setter
"access" in context => true
"has" in context.access => false
"get" in context.access => false
"set" in context.access => true

name: "foobar"
kind: accessor
"access" in context => true
"has" in context.access => false
"get" in context.access => true
"set" in context.access => true

name: "fieldOfBrokenDreams"
kind: field
"access" in context => true
"has" in context.access => false
"get" in context.access => true
"set" in context.access => true

Notice that "has" in context.access always results in false.

@lucacasonato lucacasonato added bug Something isn't working correctly upstream Changes in upstream are required to solve these issues swc related to swc (bundling/transpiling) labels Jun 18, 2024
@lucacasonato
Copy link
Member

Upstream: swc-project/swc#9079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling) upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

2 participants