Skip to content

Commit

Permalink
Merge branch 'v2' into fix/escape-url-value-in-css-url
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Mar 12, 2022
2 parents 04b13fd + ef16fad commit c4b5902
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ untyped-import
untyped-type-import

[version]
0.171.0
0.173.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/node": "^15.12.4",
"cross-env": "^7.0.0",
"eslint": "^7.20.0",
"flow-bin": "0.171.0",
"flow-bin": "0.173.0",
"glob": "^7.1.6",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@parcel/fs": "2.3.2",
"@parcel/logger": "2.3.2",
"@parcel/utils": "2.3.2",
"lmdb": "2.2.3"
"lmdb": "2.2.4"
},
"peerDependencies": {
"@parcel/core": "^2.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ if (process.env.NODE_ENV !== 'test') {
require('./true-alternate');
}

if (typeof require === "function") {
require('./true-consequent');
} else {
require('./false-alternate');
}

if (typeof exports === "object") {
require('./true-consequent');
} else {
require('./false-alternate');
}

if (typeof module === "object") {
require('./true-consequent');
} else {
require('./false-alternate');
}

module.exports = 2;
11 changes: 10 additions & 1 deletion packages/reporters/bundle-analyzer/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let foamtree = new CarrotSearchFoamTree({
<dl>
<div>
<dt>Size</dt>
<dd>${e.group.weight} bytes</dd>
<dd>${formatSize(e.group.weight)}</dd>
</div>
</dl>
</div>
Expand Down Expand Up @@ -100,3 +100,12 @@ function debounce(fn, delay) {
function translate3d(x, y, z) {
return `translate3d(${x}px, ${y}px, ${z}px)`;
}

const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
function formatSize(x) {
let l = 0, n = parseInt(x, 10) || 0;
while(n >= 1000 && ++l){
n /= 1000;
}
return(`${n.toFixed(l > 0 ? 2 : 0)} ${UNITS[l]}`);
}
20 changes: 18 additions & 2 deletions packages/reporters/cli/src/emoji.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
// @flow strict-local

const supportsEmoji =
process.platform !== 'win32' || process.env.TERM === 'xterm-256color';
// From https://github.com/sindresorhus/is-unicode-supported/blob/8f123916d5c25a87c4f966dcc248b7ca5df2b4ca/index.js
// This package is ESM-only so it has to be vendored
function isUnicodeSupported() {
if (process.platform !== 'win32') {
return process.env.TERM !== 'linux'; // Linux console (kernel)
}

return (
Boolean(process.env.CI) ||
Boolean(process.env.WT_SESSION) || // Windows Terminal
process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
process.env.TERM_PROGRAM === 'vscode' ||
process.env.TERM === 'xterm-256color' ||
process.env.TERM === 'alacritty'
);
}

const supportsEmoji = isUnicodeSupported();

// Fallback symbols for Windows from https://en.wikipedia.org/wiki/Code_page_437
export const progress: string = supportsEmoji ? '⏳' : '∞';
Expand Down
25 changes: 0 additions & 25 deletions packages/transformers/js/core/src/hoist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,31 +693,6 @@ impl<'a> Fold for Hoist<'a> {
}
}
}
Expr::Unary(ref unary) => {
// typeof require -> "function"
// typeof module -> "object"
if unary.op == UnaryOp::TypeOf {
if let Expr::Ident(ident) = &*unary.arg {
if ident.sym == js_word!("require") && !self.collect.decls.contains(&id!(ident)) {
return Expr::Lit(Lit::Str(Str {
kind: StrKind::Synthesized,
has_escape: false,
span: unary.span,
value: js_word!("function"),
}));
}

if ident.sym == js_word!("module") && !self.collect.decls.contains(&id!(ident)) {
return Expr::Lit(Lit::Str(Str {
kind: StrKind::Synthesized,
has_escape: false,
span: unary.span,
value: js_word!("object"),
}));
}
}
}
}
_ => {}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/transformers/js/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod fs;
mod global_replacer;
mod hoist;
mod modules;
mod typeof_replacer;
mod utils;

use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -49,6 +50,7 @@ use fs::inline_fs;
use global_replacer::GlobalReplacer;
use hoist::{hoist, CollectResult, HoistResult};
use modules::esm2cjs;
use typeof_replacer::*;
use utils::{CodeHighlight, Diagnostic, DiagnosticSeverity, SourceLocation, SourceType};

use crate::hoist::Collect;
Expand Down Expand Up @@ -321,6 +323,10 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
let mut diagnostics = vec![];
let module = {
let mut passes = chain!(
Optional::new(
TypeofReplacer { decls: &decls },
config.source_type != SourceType::Script
),
// Inline process.env and process.browser
Optional::new(
EnvReplacer {
Expand Down
52 changes: 52 additions & 0 deletions packages/transformers/js/core/src/typeof_replacer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::collections::HashSet;

use swc_atoms::JsWord;
use swc_ecmascript::ast::{Expr, Lit, Str, StrKind, UnaryOp};
use swc_ecmascript::visit::{Fold, FoldWith};

use crate::id;
use crate::utils::IdentId;

pub struct TypeofReplacer<'a> {
pub decls: &'a HashSet<IdentId>,
}

impl<'a> Fold for TypeofReplacer<'a> {
fn fold_expr(&mut self, node: Expr) -> Expr {
if let Expr::Unary(ref unary) = node {
// typeof require -> "function"
// typeof module -> "object"
if unary.op == UnaryOp::TypeOf {
if let Expr::Ident(ident) = &*unary.arg {
if ident.sym == js_word!("require") && !self.decls.contains(&id!(ident)) {
return Expr::Lit(Lit::Str(Str {
kind: StrKind::Synthesized,
has_escape: false,
span: unary.span,
value: js_word!("function"),
}));
}
let exports: JsWord = "exports".into();
if ident.sym == exports && !self.decls.contains(&id!(ident)) {
return Expr::Lit(Lit::Str(Str {
kind: StrKind::Synthesized,
has_escape: false,
span: unary.span,
value: js_word!("object"),
}));
}

if ident.sym == js_word!("module") && !self.decls.contains(&id!(ident)) {
return Expr::Lit(Lit::Str(Str {
kind: StrKind::Synthesized,
has_escape: false,
span: unary.span,
value: js_word!("object"),
}));
}
}
}
}
node.fold_children_with(self)
}
}
20 changes: 18 additions & 2 deletions packages/utils/create-react-app/src/emoji.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
// @flow strict-local

const supportsEmoji =
process.platform !== 'win32' || process.env.TERM === 'xterm-256color';
// From https://github.com/sindresorhus/is-unicode-supported/blob/8f123916d5c25a87c4f966dcc248b7ca5df2b4ca/index.js
// This package is ESM-only so it has to be vendored
function isUnicodeSupported() {
if (process.platform !== 'win32') {
return process.env.TERM !== 'linux'; // Linux console (kernel)
}

return (
Boolean(process.env.CI) ||
Boolean(process.env.WT_SESSION) || // Windows Terminal
process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
process.env.TERM_PROGRAM === 'vscode' ||
process.env.TERM === 'xterm-256color' ||
process.env.TERM === 'alacritty'
);
}

const supportsEmoji = isUnicodeSupported();

// Fallback symbols for Windows from https://en.wikipedia.org/wiki/Code_page_437
export const progress: string = supportsEmoji ? '⏳' : '∞';
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6118,10 +6118,10 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469"
integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA==

flow-bin@0.171.0:
version "0.171.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.171.0.tgz#43902cf3ab10704a9c8a96bd16f789d92490ba1c"
integrity sha512-2HEiXAyE60ztGs+loFk6XSskL69THL6tSjzopUcbwgfrdbuZ5Jhv23qh1jUKP5AZJh0NNwxaFZ6To2p6xR+GEA==
flow-bin@0.173.0:
version "0.173.0"
resolved "https://packages.atlassian.com/api/npm/npm-remote/flow-bin/-/flow-bin-0.173.0.tgz#4eb4b0143ffcef3ef3ee64638554a8dff6b89735"
integrity sha512-CIvShSnB4I7SsfkE9S7ECpUCkBNqDQGDWr+0uzulKGYEBnCYwFzITE1T84weLmINQwO1dR6ntsH0LlWLoGCquQ==

flush-write-stream@^1.0.0, flush-write-stream@^1.0.2:
version "1.1.1"
Expand Down Expand Up @@ -8254,10 +8254,10 @@ listr2@^2.1.0:
rxjs "^6.5.5"
through "^2.3.8"

lmdb@2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/lmdb/-/lmdb-2.2.3.tgz#713ffa515c31e042808abf364b4aa0feaeaf6360"
integrity sha512-+OiHQpw22mBBxocb/9vcVNETqf0k5vgHA2r+KX7eCf8j5tSV50ZIv388iY1mnnrERIUhs2sjKQbZhPg7z4HyPQ==
lmdb@2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/lmdb/-/lmdb-2.2.4.tgz#6494d5a1d1db152e0be759edcfa06893e4cbdb53"
integrity sha512-gto+BB2uEob8qRiTlOq+R3uX0YNHsX9mjxj9Sbdue/LIKqu6IlZjrsjKeGyOMquc/474GEqFyX2pdytpydp0rQ==
dependencies:
msgpackr "^1.5.4"
nan "^2.14.2"
Expand Down

0 comments on commit c4b5902

Please sign in to comment.