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

Bump swc #8029

Merged
merged 28 commits into from May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
411 changes: 199 additions & 212 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/core/integration-tests/test/cache.js
Expand Up @@ -4901,17 +4901,17 @@ describe('cache', function () {
},
async update(b) {
let res = await run(b.bundleGraph);
assert(res.includes("let a = 'a'"));
assert(res.includes(`let a = "a"`));

await overlayFS.writeFile(
path.join(inputDir, 'src/entries/a.js'),
"export let a = 'b';",
`export let a = "b";`,
);
},
});

let res = await run(b.bundleGraph);
assert(res.includes("let a = 'b'"));
assert(res.includes(`let a = "b"`));
});

it('should invalidate when switching to a different packager for an inline bundle', async function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/fs.js
Expand Up @@ -198,7 +198,7 @@ describe('fs', function () {
path.join(distDir, 'index.js'),
'utf8',
);
assert(contents.includes("require('fs')"));
assert(contents.includes(`require("fs")`));
assert(contents.includes('readFileSync'));

await outputFS.writeFile(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/html.js
Expand Up @@ -2549,7 +2549,7 @@ describe('html', function () {
await getNextBuild(b);

let html = await outputFS.readFile('/dist/index.html', 'utf8');
assert(html.includes("console.log('test')"));
assert(html.includes(`console.log("test")`));

await overlayFS.writeFile(
path.join(__dirname, '/html-inline-js-require/test.js'),
Expand All @@ -2558,7 +2558,7 @@ describe('html', function () {
await getNextBuild(b);

html = await outputFS.readFile(path.join(distDir, '/index.html'), 'utf8');
assert(html.includes("console.log('foo')"));
assert(html.includes(`console.log("foo")`));
});

it('should invalidate parent bundle when nested inline bundles change', async function () {
Expand Down
@@ -0,0 +1,4 @@
import {B} from './b.js';
import {C} from './c.js';

output = [new B()[Symbol.toStringTag], new C()[Symbol.toStringTag]];
@@ -0,0 +1,5 @@
export class B {
get [Symbol.toStringTag]() {
return '1';
}
}
@@ -0,0 +1,5 @@
export class C {
get [Symbol.toStringTag]() {
return '2';
}
}
@@ -0,0 +1,3 @@
{
"browserslist": "Chrome 50"
}
Expand Up @@ -4,6 +4,6 @@ console.log('bar');
/* block comment line */
console.log('baz');
/* multi line
block comment
block comment
*/
console.log('idhf');
18 changes: 9 additions & 9 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -1084,8 +1084,8 @@ describe('javascript', function () {
let main = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
dedicated = await outputFS.readFile(dedicated.filePath, 'utf8');
shared = await outputFS.readFile(shared.filePath, 'utf8');
assert(/new Worker(.*?, {[\n\s]+type: 'module'[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+type: 'module'[\n\s]+})/.test(main));
assert(/new Worker(.*?, {[\n\s]+type: "module"[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+type: "module"[\n\s]+})/.test(main));
});

for (let shouldScopeHoist of [true, false]) {
Expand Down Expand Up @@ -1238,8 +1238,8 @@ describe('javascript', function () {
);

let main = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(/new Worker(.*?, {[\n\s]+name: 'worker'[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+name: 'shared'[\n\s]+})/.test(main));
assert(/new Worker(.*?, {[\n\s]+name: "worker"[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+name: "shared"[\n\s]+})/.test(main));
});

it('should error if importing in a worker without type: module', async function () {
Expand Down Expand Up @@ -1438,7 +1438,7 @@ describe('javascript', function () {
]);

let res = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(res.includes("importScripts('imported.js')"));
assert(res.includes(`importScripts("imported.js")`));
});

it('should ignore importScripts in script workers when not passed a string literal', async function () {
Expand Down Expand Up @@ -1484,7 +1484,7 @@ describe('javascript', function () {
]);

let res = await outputFS.readFile(b.getBundles()[1].filePath, 'utf8');
assert(res.includes("importScripts('https://unpkg.com/parcel')"));
assert(res.includes(`importScripts("https://unpkg.com/parcel")`));
});

it('should support bundling service-workers', async function () {
Expand Down Expand Up @@ -1559,7 +1559,7 @@ describe('javascript', function () {
let main = bundles.find(b => !b.env.isWorker());
let mainContents = await outputFS.readFile(main.filePath, 'utf8');
assert(
/navigator.serviceWorker.register\(.*?, {[\n\s]*scope: 'foo'[\n\s]*}\)/.test(
/navigator.serviceWorker.register\(.*?, {[\n\s]*scope: "foo"[\n\s]*}\)/.test(
mainContents,
),
);
Expand Down Expand Up @@ -4384,7 +4384,7 @@ describe('javascript', function () {
let res = await run(b);
assert.equal(
res.default,
"<p>test</p>\n<script>console.log('hi');\n\n</script>\n",
`<p>test</p>\n<script>console.log("hi");\n\n</script>\n`,
);
});

Expand Down Expand Up @@ -5556,7 +5556,7 @@ describe('javascript', function () {
},
end: {
line: 1,
column: 0,
column: 1,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/output-formats.js
Expand Up @@ -987,7 +987,7 @@ describe('output formats', function () {
assert.equal(await res.output, 4);
});

it('should support use an import polyfill for older browsers', async function () {
it('should support using an import polyfill for older browsers', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/esm-browser/index.html'),
{
Expand Down Expand Up @@ -1024,7 +1024,7 @@ describe('output formats', function () {
.find(bundle => bundle.name.startsWith('async'));
assert(
new RegExp(
"getBundleURL\\('[a-zA-Z0-9]+'\\) \\+ \"" +
`getBundleURL\\("[a-zA-Z0-9]+"\\) \\+ "` +
path.basename(asyncBundle.filePath) +
'"',
).test(entry),
Expand Down
17 changes: 17 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -169,6 +169,23 @@ describe('scope hoisting', function () {
assert.equal(output, 2);
});

it('supports renaming helpers inserted during transpiling', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/rename-helpers/a.js',
),
);
let contents = await outputFS.readFile(
b.getBundles()[0].filePath,
'utf8',
);
assert(/let \S* = Symbol.toStringTag;/.test(contents));

let output = await run(b);
assert.deepEqual(output, ['1', '2']);
});

it('supports renaming imports', async function () {
let b = await bundle(
path.join(
Expand Down
71 changes: 52 additions & 19 deletions packages/core/integration-tests/test/sourcemaps.js
@@ -1,6 +1,9 @@
// @flow
import assert from 'assert';
import invariant from 'assert';
import path from 'path';
import SourceMap from '@parcel/source-map';
import type {InitialParcelOptions} from '@parcel/types';
import {
bundle as _bundle,
inputFS,
Expand All @@ -11,11 +14,11 @@ import {
mergeParcelOptions,
} from '@parcel/test-utils';
import {loadSourceMapUrl} from '@parcel/utils';
import nullthrows from 'nullthrows';

const bundle = (name, opts = {}) => {
const bundle = (name, opts?: InitialParcelOptions) => {
return _bundle(
name,
// $FlowFixMe
mergeParcelOptions(
{
defaultTargetOptions: {
Expand Down Expand Up @@ -43,7 +46,15 @@ function checkSourceMapping({
generatedStr = str,
sourcePath,
msg = '',
}) {
}: {|
map: SourceMap,
source: string,
generated: string,
str: string,
generatedStr?: string,
sourcePath: string,
msg?: string,
|}) {
assert(
generated.indexOf(generatedStr) !== -1,
"'" + generatedStr + "' not found in generated code",
Expand Down Expand Up @@ -90,13 +101,14 @@ function checkSourceMapping({
mapping = map.indexedMappingToStringMapping(mappings[closestIndex]);
}

assert(mapping, "no mapping for '" + str + "'" + msg);
invariant(mapping, "no mapping for '" + str + "'" + msg);

let generatedDiff = {
line: generatedPosition.line - mapping.generated.line,
column: generatedPosition.column - mapping.generated.column,
};

invariant(mapping.original);
let computedSourcePosition = {
line: mapping.original.line + generatedDiff.line,
column: mapping.original.column + generatedDiff.column,
Expand Down Expand Up @@ -610,7 +622,9 @@ describe('sourcemaps', function () {
'/integration/sourcemap-css/style.css',
);

await bundle(inputFilePath, {minify});
await bundle(inputFilePath, {
defaultTargetOptions: {shouldOptimize: minify},
});
let distDir = path.join(__dirname, '../dist/');
let filename = path.join(distDir, 'style.css');
let raw = await outputFS.readFile(filename, 'utf8');
Expand Down Expand Up @@ -656,7 +670,9 @@ describe('sourcemaps', function () {
'/integration/sourcemap-css-import/style.css',
);

await bundle(inputFilePath, {minify});
await bundle(inputFilePath, {
defaultTargetOptions: {shouldOptimize: minify},
});
let distDir = path.join(__dirname, '../dist/');
let filename = path.join(distDir, 'style.css');
let raw = await outputFS.readFile(filename, 'utf8');
Expand All @@ -673,22 +689,33 @@ describe('sourcemaps', function () {
sourceMap.addVLQMap(map);

let mapData = sourceMap.getMap();
assert.deepEqual(mapData.sources, [
'other-style.css',
'another-style.css',
'style.css',
]);
let sources = minify
? ['style.css', 'other-style.css', 'another-style.css']
: ['other-style.css', 'another-style.css', 'style.css'];
assert.deepEqual(mapData.sources, sources);

let otherStyle = await inputFS.readFile(
path.join(path.dirname(filename), map.sourceRoot, map.sources[0]),
path.join(
path.dirname(filename),
map.sourceRoot,
map.sources[sources.indexOf('other-style.css')],
),
'utf-8',
);
let anotherStyle = await inputFS.readFile(
path.join(path.dirname(filename), map.sourceRoot, map.sources[1]),
path.join(
path.dirname(filename),
map.sourceRoot,
map.sources[sources.indexOf('another-style.css')],
),
'utf-8',
);
let style = await inputFS.readFile(
path.join(path.dirname(filename), map.sourceRoot, map.sources[2]),
path.join(
path.dirname(filename),
map.sourceRoot,
map.sources[sources.indexOf('style.css')],
),
'utf8',
);

Expand Down Expand Up @@ -1123,7 +1150,9 @@ describe('sourcemaps', function () {
__dirname,
'/integration/sourcemap-css-existing/style.css',
);
let b = await bundle(sourceFilename, {minify});
let b = await bundle(sourceFilename, {
defaultTargetOptions: {shouldOptimize: minify},
});

let filename = b.getBundles()[0].filePath;
let raw = await outputFS.readFile(filename, 'utf8');
Expand Down Expand Up @@ -1228,6 +1257,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('foo')",
generatedStr: `console.log("foo")`,
sourcePath,
});

Expand All @@ -1236,6 +1266,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('bar')",
generatedStr: `console.log("bar")`,
sourcePath,
});

Expand All @@ -1244,6 +1275,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('baz')",
generatedStr: `console.log("baz")`,
sourcePath,
});

Expand All @@ -1252,6 +1284,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('idhf')",
generatedStr: `console.log("idhf")`,
sourcePath,
});
});
Expand Down Expand Up @@ -1281,7 +1314,7 @@ describe('sourcemaps', function () {
let sourceMap = new SourceMap('/');
sourceMap.addVLQMap(map);
let sourcePath = 'index.js';
let sourceContent = sourceMap.getSourceContent(sourcePath);
let sourceContent = nullthrows(sourceMap.getSourceContent(sourcePath));

checkSourceMapping({
map: sourceMap,
Expand Down Expand Up @@ -1326,7 +1359,7 @@ describe('sourcemaps', function () {
let sourceMap = new SourceMap('/');
sourceMap.addVLQMap(map);
let sourcePath = 'index.tsx';
let sourceContent = sourceMap.getSourceContent(sourcePath);
let sourceContent = nullthrows(sourceMap.getSourceContent(sourcePath));

checkSourceMapping({
map: sourceMap,
Expand Down Expand Up @@ -1390,8 +1423,8 @@ describe('sourcemaps', function () {
map: sourceMap,
source: sourceContent,
generated: raw,
str: "foo = 'Lorem ipsum",
generatedStr: "foo = 'Lorem ipsum",
str: `foo = 'Lorem ipsum`,
generatedStr: `foo = "Lorem ipsum`,
sourcePath,
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/svg.js
Expand Up @@ -195,7 +195,7 @@ describe('svg', function () {
),
);
assert(svg.includes('<script>'));
assert(svg.includes("console.log('script')"));
assert(svg.includes(`console.log("script")`));
assert(!svg.includes('import '));
});

Expand Down
2 changes: 1 addition & 1 deletion packages/optimizers/image/src/lib.rs
Expand Up @@ -43,7 +43,7 @@ fn optimize(ctx: CallContext) -> Result<JsBuffer> {
if let Some(msg) = err.downcast_ref::<String>() {
Err(Error::from_reason(msg.to_string()))
} else {
Err(Error::from_reason("Unknown libjpeg error".into()))
Err(Error::from_reason("Unknown libjpeg error"))
}
}
}
Expand Down