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

Reference Error while processing enum with --no-check option #13026

Closed
kt3k opened this issue Dec 9, 2021 · 4 comments · Fixed by #13051
Closed

Reference Error while processing enum with --no-check option #13026

kt3k opened this issue Dec 9, 2021 · 4 comments · Fixed by #13051
Assignees
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)
Milestone

Comments

@kt3k
Copy link
Member

kt3k commented Dec 9, 2021

The canary build throws with the following enum (when --no-check option is passed):

export enum Encodings {
  ASCII,
  UTF8,
  BASE64,
  UCS2,
  BINARY,
  HEX,
  BUFFER,
  BASE64URL,
  LATIN1 = BINARY,
}

(ref: https://github.com/denoland/deno_std/blob/21e0b73979466202e738f458ff0b9232b21dd4e1/node/internal_binding/_node.ts )

It throws with ReferenceError: BINARY is not defined only when --no-check is specified.

I guess this might be related to #13025. cc @dsherret

@kitsonk kitsonk added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Dec 9, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Dec 9, 2021

That feels like really fragile and dodgy code, but it is valid TypeScript.

@kt3k
Copy link
Member Author

kt3k commented Dec 9, 2021

I didn't know this syntax is possible until I saw the above error..

BTW std now dropped the usage of this syntax. So this issue isn't urgent from std's perspective now. denoland/std#1694

@dsherret dsherret self-assigned this Dec 9, 2021
@dsherret
Copy link
Member

dsherret commented Dec 9, 2021

Given:

var x = 5;
enum Foo {
    a,
    b = a,
    c = b + 1,
    d = 1 + c * x,
    e = 2 * d
}

Swc:

var x = 5;
var Foo;
(function(Foo) {
    Foo[Foo["a"] = 0] = "a";
    Foo[Foo["b"] = a] = "b";
    Foo[Foo["c"] = b + 1] = "c";
    Foo[Foo["d"] = 1 + c * x] = "d";
    Foo[Foo["e"] = 2 * d] = "e";
})(Foo || (Foo = {
}));

TypeScript:

var x = 5;
var Foo;
(function (Foo) {
    Foo[Foo["a"] = 0] = "a";
    Foo[Foo["b"] = 0] = "b";
    Foo[Foo["c"] = 1] = "c";
    Foo[Foo["d"] = 1 + Foo.c * x] = "d";
    Foo[Foo["e"] = 2 * Foo.d] = "e";
})(Foo || (Foo = {}));

I'll fix this.

By the way, this is done a lot for things like enum flags (ex. All = Member1 | Member2) so it is fairly common.

@dsherret
Copy link
Member

dsherret commented Dec 9, 2021

Opened swc-project/swc#3000

@dsherret dsherret added this to the 1.17.0 milestone Dec 9, 2021
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)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants