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 20 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.

@@ -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"
}
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/javascript.js
Expand Up @@ -5522,7 +5522,7 @@ describe('javascript', function () {
},
end: {
line: 1,
column: 0,
column: 1,
},
},
],
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
63 changes: 46 additions & 17 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 @@ -1281,7 +1310,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 +1355,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
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
4 changes: 2 additions & 2 deletions packages/transformers/js/core/Cargo.toml
Expand Up @@ -8,8 +8,8 @@ edition = "2018"
crate-type = ["rlib"]

[dependencies]
swc_ecmascript = { version = "0.143.0", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils", "preset_env"] }
swc_common = { version = "0.17.21", features = ["tty-emitter", "sourcemap"] }
swc_ecmascript = { version = "0.156.0", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils", "preset_env"] }
swc_common = { version = "0.18.0", features = ["tty-emitter", "sourcemap"] }
swc_atoms = "0.2.11"
indoc = "1.0.3"
serde = "1.0.123"
Expand Down
1 change: 0 additions & 1 deletion packages/transformers/js/core/src/dependency_collector.rs
Expand Up @@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::{Mark, SourceMap, Span, SyntaxContext, DUMMY_SP};
use swc_ecmascript::ast::{self, Callee, MemberProp};
use swc_ecmascript::utils::ident::IdentLike;
use swc_ecmascript::visit::{Fold, FoldWith};

use crate::fold_member_expr_skip_prop;
Expand Down