Skip to content

Commit

Permalink
Set ascii_only for swc emit
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Sep 13, 2023
1 parent f52762f commit c5e6f5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
distDir,
outputFS,
inputFS,
fsFixture,
} from '@parcel/test-utils';
import {makeDeferredWithPromise, normalizePath} from '@parcel/utils';
import vm from 'vm';
Expand Down Expand Up @@ -6326,6 +6327,26 @@ describe('javascript', function () {
assert.equal(await res.default, 'target');
});

it('should retain unicode escape sequences', async function () {
await fsFixture(overlayFS, __dirname)`
src/index.js:
export default ['\\u0085', '\\u200b', '\\ufffe'];
`;

let b = await bundle(path.join(__dirname, 'src/index.js'), {
inputFS: overlayFS,
});

let output = (await run(b)).default;
assert.deepEqual(output, ['\u0085', '\u200b', '\ufffe']);

let contents = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(contents.match(/\\/g).length, 3);
assert(!contents.includes('\u0085'));
assert(!contents.includes('\u200b'));
assert(!contents.includes('\ufffe'));
});

for (let shouldScopeHoist of [false, true]) {
let options = {
defaultTargetOptions: {
Expand Down
5 changes: 3 additions & 2 deletions packages/transformers/js/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,9 @@ fn emit(
None
},
));
let config =
swc_core::ecma::codegen::Config::default().with_target(swc_core::ecma::ast::EsVersion::Es5);
let config = swc_core::ecma::codegen::Config::default()
.with_target(swc_core::ecma::ast::EsVersion::Es5)
.with_ascii_only(true);
let mut emitter = swc_core::ecma::codegen::Emitter {
cfg: config,
comments: Some(&comments),
Expand Down

0 comments on commit c5e6f5f

Please sign in to comment.