Skip to content

Commit

Permalink
Bump swc (#7487)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Dec 29, 2021
1 parent f094a8e commit 13649c3
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 108 deletions.
211 changes: 122 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

Expand Up @@ -7,6 +7,7 @@
"react": "preact/compat",
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat",
"react/jsx-runtime": "preact/jsx-runtime"
"react/jsx-runtime": "preact/jsx-runtime",
"react/jsx-dev-runtime": "preact/jsx-dev-runtime"
}
}
16 changes: 8 additions & 8 deletions packages/core/integration-tests/test/transpilation.js
Expand Up @@ -178,8 +178,8 @@ describe('transpilation', function () {
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(file.includes('react/jsx-runtime'));
assert(file.includes('_jsxRuntime.jsx("div"'));
assert(file.includes('react/jsx-dev-runtime'));
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support the automatic JSX runtime with preact >= 10.5', async function () {
Expand All @@ -188,8 +188,8 @@ describe('transpilation', function () {
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(file.includes('preact/jsx-runtime'));
assert(file.includes('_jsxRuntime.jsx("div"'));
assert(file.includes('preact/jsx-dev-runtime'));
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support the automatic JSX runtime with preact with alias', async function () {
Expand All @@ -201,8 +201,8 @@ describe('transpilation', function () {
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(/\Wreact\/jsx-runtime\W/.test(file));
assert(file.includes('_jsxRuntime.jsx("div"'));
assert(/\Wreact\/jsx-dev-runtime\W/.test(file));
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support the automatic JSX runtime with explicit tsconfig.json', async function () {
Expand All @@ -211,8 +211,8 @@ describe('transpilation', function () {
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(file.includes('preact/jsx-runtime'));
assert(file.includes('_jsxRuntime.jsx("div"'));
assert(file.includes('preact/jsx-dev-runtime'));
assert(file.includes('_jsxDevRuntime.jsxDEV("div"'));
});

it('should support explicit JSX pragma in tsconfig.json', async function () {
Expand Down
5 changes: 2 additions & 3 deletions packages/transformers/js/core/Cargo.toml
Expand Up @@ -8,9 +8,8 @@ edition = "2018"
crate-type = ["rlib"]

[dependencies]
swc_ecmascript = { version = "0.95.0", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils"] }
swc_ecma_preset_env = "0.73.0"
swc_common = { version = "0.15.0", features = ["tty-emitter", "sourcemap"] }
swc_ecmascript = { version = "0.99.9", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils", "preset_env"] }
swc_common = { version = "0.15.1", features = ["tty-emitter", "sourcemap"] }
swc_atoms = "0.2.9"
indoc = "1.0.3"
serde = "1.0.123"
Expand Down
4 changes: 2 additions & 2 deletions packages/transformers/js/core/src/hoist.rs
Expand Up @@ -886,7 +886,7 @@ impl<'a> Fold for Hoist<'a> {

if is_cjs_exports {
let key: JsWord = if self.collect.static_cjs_exports {
if let Some((name, _)) = match_property_name(&member) {
if let Some((name, _)) = match_property_name(member) {
name
} else {
unreachable!("Unexpected non-static CJS export");
Expand Down Expand Up @@ -1701,7 +1701,7 @@ impl Visit for Collect {
}

// `import` isn't really an identifier...
if match_property_name(&node).is_none() && ident.sym != js_word!("import") {
if match_property_name(node).is_none() && ident.sym != js_word!("import") {
self
.non_static_access
.entry(id!(ident))
Expand Down
5 changes: 2 additions & 3 deletions packages/transformers/js/core/src/lib.rs
@@ -1,5 +1,4 @@
extern crate swc_common;
extern crate swc_ecma_preset_env;
extern crate swc_ecmascript;
#[macro_use]
extern crate swc_atoms;
Expand Down Expand Up @@ -30,11 +29,11 @@ use serde::{Deserialize, Serialize};
use swc_common::comments::SingleThreadedComments;
use swc_common::errors::{DiagnosticBuilder, Emitter, Handler};
use swc_common::{chain, sync::Lrc, FileName, Globals, Mark, SourceMap};
use swc_ecma_preset_env::{preset_env, Mode::Entry, Targets, Version, Versions};
use swc_ecmascript::ast::Module;
use swc_ecmascript::codegen::text_writer::JsWriter;
use swc_ecmascript::parser::lexer::Lexer;
use swc_ecmascript::parser::{EsConfig, PResult, Parser, StringInput, Syntax, TsConfig};
use swc_ecmascript::preset_env::{preset_env, Mode::Entry, Targets, Version, Versions};
use swc_ecmascript::transforms::resolver::resolver_with_mark;
use swc_ecmascript::transforms::{
compat::reserved_words::reserved_words, fixer, helpers, hygiene,
Expand Down Expand Up @@ -301,7 +300,7 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {

let mut decls = collect_decls(&module);

let mut preset_env_config = swc_ecma_preset_env::Config {
let mut preset_env_config = swc_ecmascript::preset_env::Config {
dynamic_import: true,
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/js/core/src/modules.rs
Expand Up @@ -2,8 +2,8 @@ use inflector::Inflector;
use std::collections::{HashMap, HashSet};
use swc_atoms::JsWord;
use swc_common::{Mark, Span, SyntaxContext, DUMMY_SP};
use swc_ecma_preset_env::{Feature, Versions};
use swc_ecmascript::ast::*;
use swc_ecmascript::preset_env::{Feature, Versions};
use swc_ecmascript::visit::{Fold, FoldWith};

use crate::fold_member_expr_skip_prop;
Expand Down
7 changes: 6 additions & 1 deletion packages/transformers/js/src/JSTransformer.js
Expand Up @@ -662,7 +662,12 @@ export default (new Transformer({
}

// Always bundle helpers, even with includeNodeModules: false, except if this is a library.
let isHelper = dep.is_helper && !dep.specifier.endsWith('/jsx-runtime');
let isHelper =
dep.is_helper &&
!(
dep.specifier.endsWith('/jsx-runtime') ||
dep.specifier.endsWith('/jsx-dev-runtime')
);
if (isHelper && !asset.env.isLibrary) {
env = {
...env,
Expand Down

0 comments on commit 13649c3

Please sign in to comment.