diff options
author | 2022-10-13 20:44:08 +0800 | |
---|---|---|
committer | 2022-10-13 05:44:08 -0700 | |
commit | b542921f3db7a0439c53883a93187a8fc8f5bdb3 (patch) | |
tree | 039f0cd6fe3db8734e0da3ccc13d9bda7ed70028 | |
parent | b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e (diff) | |
download | bun-b542921f3db7a0439c53883a93187a8fc8f5bdb3.tar.gz bun-b542921f3db7a0439c53883a93187a8fc8f5bdb3.tar.zst bun-b542921f3db7a0439c53883a93187a8fc8f5bdb3.zip |
Fix import alias (#1313)
-rw-r--r-- | src/bun.js/api/transpiler.zig | 1 | ||||
-rw-r--r-- | src/js_printer.zig | 2 | ||||
-rw-r--r-- | test/bun.js/transpiler.test.js | 8 |
3 files changed, 10 insertions, 1 deletions
diff --git a/src/bun.js/api/transpiler.zig b/src/bun.js/api/transpiler.zig index 24678850f..b512fb776 100644 --- a/src/bun.js/api/transpiler.zig +++ b/src/bun.js/api/transpiler.zig @@ -1119,6 +1119,7 @@ pub fn transformSync( buffer_writer = printer.ctx; var out = JSC.ZigString.init(buffer_writer.written); out.mark(); + out.setOutputEncoding(); return out.toValueGC(ctx.ptr()).asObjectRef(); } diff --git a/src/js_printer.zig b/src/js_printer.zig index edb4bc35e..343911baf 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -881,7 +881,7 @@ pub fn NewPrinter( p.printIdentifier(name); } pub fn printClauseAlias(p: *Printer, alias: string) void { - if (p.canPrintIdentifier(alias)) { + if (!strings.containsNonBmpCodePoint(alias)) { p.printSpaceBeforeIdentifier(); p.printIdentifier(alias); } else { diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js index e10e4339f..855046911 100644 --- a/test/bun.js/transpiler.test.js +++ b/test/bun.js/transpiler.test.js @@ -1747,6 +1747,14 @@ class Foo { expect(out.includes("otherNamesStillWork")).toBe(true); }); + it("special identifier in import statement", () => { + const out = transpiler.transformSync(` + import {ɵtest} from 'foo' + `); + + expect(out).toBe("import {ɵtest} from \"foo\";\n"); + }); + const importLines = [ "import {createElement, bacon} from 'react';", "import {bacon, createElement} from 'react';", |