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

fix(bundler): Fix bugs #1346

Merged
merged 37 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1cf0ffa
Add a test for #1345
kdy1 Jan 21, 2021
633d0ef
Disable minify
kdy1 Jan 21, 2021
bbe40ec
Add a test for denoland/deno#9055
kdy1 Jan 21, 2021
f9f14ea
Move
kdy1 Jan 21, 2021
912630c
Update test refs
kdy1 Jan 21, 2021
e46b54a
Add a test for denoland/deno#9055
kdy1 Jan 21, 2021
ca4690c
Fix keywords pass.
kdy1 Jan 21, 2021
03680da
Update test refs
kdy1 Jan 21, 2021
3d6df3d
Add a test for denoland/deno#9200
kdy1 Jan 21, 2021
a966618
Remove dbg!
kdy1 Jan 21, 2021
a461c54
Add a small test for denoland/deno#9200
kdy1 Jan 21, 2021
c781143
fixup
kdy1 Jan 21, 2021
287d9a8
DEBUG
kdy1 Jan 21, 2021
9a22728
DEBUG: Print prepared
kdy1 Jan 21, 2021
4e90e95
Add one more test case to find root cause.
kdy1 Jan 21, 2021
6376b8c
More prints
kdy1 Jan 21, 2021
cf79f40
Ignore 9200
kdy1 Jan 22, 2021
9275eab
Add a test for denoland/deno#9212
kdy1 Jan 22, 2021
56c5672
Add a test for denoland/deno#9219
kdy1 Jan 22, 2021
546d525
Add a test for denoland/deno#9220
kdy1 Jan 22, 2021
bc8194c
9219 was an issue of keywords psss.
kdy1 Jan 22, 2021
7cd4287
Update test refs
kdy1 Jan 22, 2021
ce28c8e
Const propagation: Remove only injected variables.
kdy1 Jan 22, 2021
4e953aa
fixup for const propagation
kdy1 Jan 22, 2021
8104323
Update tets refs
kdy1 Jan 22, 2021
f6310c4
Fix denoland/deno#9220
kdy1 Jan 22, 2021
fdeb4d7
Move test file
kdy1 Jan 22, 2021
ea6068e
Ignore 9212 and 9200
kdy1 Jan 22, 2021
f3e0b7d
Update test refs
kdy1 Jan 22, 2021
65fc59b
Disable debug utils
kdy1 Jan 22, 2021
a36d167
fixup
kdy1 Jan 22, 2021
9c1f333
Ignore 9200
kdy1 Jan 22, 2021
a1a8000
Remove wrong env var
kdy1 Jan 22, 2021
9535e1d
Check if yaml placeholders work
kdy1 Jan 22, 2021
cd81d1d
Revert "Check if yaml placeholders work"
kdy1 Jan 22, 2021
d447346
Use matrix
kdy1 Jan 22, 2021
b945e32
fix
kdy1 Jan 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ on: [push, pull_request]

env:
CARGO_INCREMENTAL: 0
# To make spack tests reliable
RAYON_NUM_THREADS: 1
CI: "1"

jobs:
Expand All @@ -29,9 +27,59 @@ jobs:
- name: Run cargo fmt
run: cargo fmt --all -- --check

check-all:
name: Compilability
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Ensure that all components all compilable.
- name: Run cargo check for all targets
run: cargo check --color always --all --all-targets

test:
name: test
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
crate:
- ast_node
- enum_kind
- from_variant
- jsdoc
- spack
- string_enum
- swc
- swc_atoms
- swc_bundler
- swc_common
- swc_ecma_ast
- swc_ecma_codegen
- swc_ecma_codegen_macros
- swc_ecma_dep_graph
- swc_ecma_ext_transforms
- swc_ecma_parser
- swc_ecma_preset_env
- swc_ecma_transforms
- swc_ecma_transforms_base
- swc_ecma_transforms_compat
- swc_ecma_transforms_macros
- swc_ecma_transforms_module
- swc_ecma_transforms_optimization
- swc_ecma_transforms_proposal
- swc_ecma_transforms_react
- swc_ecma_transforms_testing
- swc_ecma_transforms_typescript
- swc_ecma_utils
- swc_ecma_visit
- swc_ecmascript
- swc_eq_ignore_macros
- swc_macros_common
- swc_visit
- swc_visit_macros
- testing
- testing_macros

steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -60,14 +108,10 @@ jobs:
**/target/
key: ${{ runner.os }}-cargo-test

# Ensure that all components all compilable.
- name: Run cargo check for all targets
run: cargo check --color always --all --all-targets

- name: Run cargo test
run: |
export PATH="$PATH:$HOME/npm/bin"
cargo test --color always --all --exclude node --exclude wasm
cargo test --color always -p ${{ matrix.crate }}
#
deploy-docs:
runs-on: ubuntu-latest
Expand Down
12 changes: 12 additions & 0 deletions bundler/src/bundler/chunk/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ where
// );
}

// print_hygiene(
// &format!("processed: {}", info.fm.name),
// &self.cm,
// &module.clone().into(),
// );

if is_entry {
self.replace_import_specifiers(&info, &mut module);
self.finalize_merging_of_entry(ctx, &mut module);
Expand Down Expand Up @@ -1043,6 +1049,12 @@ where

new
});

// print_hygiene(
// &format!("prepared: {}", info.fm.name),
// &self.cm,
// &module.clone().into(),
// );
}

pub(super) fn replace_import_specifiers(&self, info: &TransformedModule, module: &mut Modules) {
Expand Down
33 changes: 29 additions & 4 deletions bundler/src/bundler/keywords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::id::Id;
use crate::util::MapWithMut;
use std::collections::HashMap;
use swc_atoms::js_word;
use swc_ecma_ast::*;
Expand Down Expand Up @@ -65,11 +66,35 @@ impl VisitMut for KeywordRenamer {
}
}

fn visit_mut_assign_pat_prop(&mut self, n: &mut AssignPatProp) {
if let Some(renamed) = self.renamed(&n.key) {
n.key = renamed;
fn visit_mut_object_pat_prop(&mut self, n: &mut ObjectPatProp) {
n.visit_mut_children_with(self);

match n {
ObjectPatProp::Assign(pat) => {
if let Some(renamed) = self.renamed(&pat.key) {
match &mut pat.value {
Some(default) => {
*n = ObjectPatProp::KeyValue(KeyValuePatProp {
key: PropName::Ident(pat.key.take()),
value: Box::new(Pat::Assign(AssignPat {
span: pat.span,
left: Box::new(Pat::Ident(renamed)),
right: default.take(),
type_ann: None,
})),
});
}
None => {
*n = ObjectPatProp::KeyValue(KeyValuePatProp {
key: PropName::Ident(pat.key.take()),
value: Box::new(Pat::Ident(renamed)),
})
}
}
}
}
_ => {}
}
n.value.visit_mut_with(self);
}

fn visit_mut_pat(&mut self, n: &mut Pat) {
Expand Down
3 changes: 3 additions & 0 deletions bundler/tests/deno-exec/.deno-9200/case1/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { isEmail } from "https://deno.land/x/segno@v1.1.0/mod.ts";

isEmail("test@test.com");
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const a1 = 'a';
const a2 = 'a';
const c1 = 'c';
const a1 = a2;
export { a1 as a };
export { c1 as c };
3 changes: 2 additions & 1 deletion bundler/tests/fixture/deno-8978/output/entry.inlined.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const f = ()=>"hello world"
;
export { f as any };
const any1 = f;
export { any1 as any };
9 changes: 9 additions & 0 deletions bundler/tests/fixture/deno-9055/keywords-1/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const x = {
n: 123,
t: 'text',
int: '==INT=='
}

const { n, t, int } = x

console.log(n, t, int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const x = {
n: 123,
t: 'text',
int: '==INT=='
};
const { n , t , int: __int } = x;
console.log(n, t, __int);
7 changes: 7 additions & 0 deletions bundler/tests/fixture/deno-9055/keywords-1/output/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const x = {
n: 123,
t: 'text',
int: '==INT=='
};
const { n , t , int: __int } = x;
console.log(n, t, __int);
9 changes: 9 additions & 0 deletions bundler/tests/fixture/deno-9055/keywords-2/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const x = {
n: 123,
t: 'text',
int: '==INT=='
}

const { n, t, int = 5 } = x

console.log(n, t, int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const x = {
n: 123,
t: 'text',
int: '==INT=='
};
const { n , t , int: __int = 5 } = x;
console.log(n, t, __int);
7 changes: 7 additions & 0 deletions bundler/tests/fixture/deno-9055/keywords-2/output/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const x = {
n: 123,
t: 'text',
int: '==INT=='
};
const { n , t , int: __int = 5 } = x;
console.log(n, t, __int);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class MyError extends Error {
super("I'm in?");
}
}
function example1() {
function example2() {
throw new MyError();
}
const example1 = example2;
export { example1 as example };
7 changes: 7 additions & 0 deletions bundler/tests/fixture/deno-9200/.case1/input/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as lib from './lib';

// exporting all functions
export * from './lib';

// exporting functions namespaced to segno
export { lib };
2 changes: 2 additions & 0 deletions bundler/tests/fixture/deno-9200/.case1/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { foo } from './deps'
foo()
1 change: 1 addition & 0 deletions bundler/tests/fixture/deno-9200/.case1/input/lib-impl1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function foo() { }
1 change: 1 addition & 0 deletions bundler/tests/fixture/deno-9200/.case1/input/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib-impl1'
7 changes: 7 additions & 0 deletions bundler/tests/fixture/deno-9200/.case2/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as lib from './lib';

// exporting all functions
export * from './lib';

// exporting functions namespaced to segno
export { lib };
1 change: 1 addition & 0 deletions bundler/tests/fixture/deno-9200/.case2/input/lib-impl1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function foo() { }
1 change: 1 addition & 0 deletions bundler/tests/fixture/deno-9200/.case2/input/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib-impl1'
6 changes: 6 additions & 0 deletions bundler/tests/fixture/deno-9212/.case1/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as ReactDom from "https://esm.sh/react-dom@17.0.1"
import * as React from "https://esm.sh/react@17.0.1"

const { document } = window as any

ReactDom.render(React.createElement('p', null, 'hello world!'), document.body)
21 changes: 21 additions & 0 deletions bundler/tests/fixture/deno-9219/case1/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { parse } from "https://deno.land/std@0.84.0/flags/mod.ts";

const args = parse(Deno.args, {
boolean: [
"help",
"verbose",
],
alias: {
help: "h",
verbose: "v",
},
default: {
verbose: false,
},
}) as {
_: string[];
help: boolean;
verbose: boolean;
};

console.dir(args);
Loading