fix(bundler): Fix bugs (#1373)

swc_bundler:
- Handle export default-ed functions correctly.
This commit is contained in:
강동윤 2021-02-01 12:31:03 +09:00 committed by GitHub
parent 0d130f8103
commit bfde9a1f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 337 additions and 204 deletions

View File

@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"]
license = "Apache-2.0/MIT" license = "Apache-2.0/MIT"
name = "swc_bundler" name = "swc_bundler"
repository = "https://github.com/swc-project/swc.git" repository = "https://github.com/swc-project/swc.git"
version = "0.20.8" version = "0.20.9"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]

View File

@ -929,9 +929,18 @@ where
)) ))
} }
None => { None => {
let init = Expr::Fn(f); // We should inject a function declaration because of
// dependencies.
//
// See: https://github.com/denoland/deno/issues/9346
let ident = private_ident!("default");
new.push(ModuleItem::Stmt(Stmt::Decl(Decl::Fn(FnDecl {
ident: ident.clone(),
function: f.function,
declare: false,
}))));
new.push(init.assign_to(local.clone()).into_module_item( new.push(ident.assign_to(local.clone()).into_module_item(
injected_ctxt, injected_ctxt,
"prepare -> export default decl -> function -> \ "prepare -> export default decl -> function -> \
without ident", without ident",

View File

@ -0,0 +1,13 @@
import { parse } from "https://deno.land/std@0.85.0/flags/mod.ts";
import { getNumericInput, printQuestion } from "./helpers/mod";
import printStats from "./print_stats.ts";
const args = parse(Deno.args);
console.log(args.stats);
printStats();
printQuestion("How many times have you played");
console.log(await getNumericInput());

View File

@ -0,0 +1,14 @@
import { TRIVIA } from "../types/mod";
import { getUserInput, printQuestion } from "./mod";
export async function askTriviaQuestion(
selectedTrivia: TRIVIA,
): Promise<void> {
printQuestion(selectedTrivia.question);
await getUserInput();
console.log("The correct answer is:", selectedTrivia.correctAnswer);
console.log("Source:", selectedTrivia.source.name, "\n");
}

View File

@ -0,0 +1,6 @@
import { SOURCE } from "../types/mod";
export const generateTVSource = (name: string): SOURCE => ({
name,
mediaType: "Television",
});

View File

@ -0,0 +1,12 @@
import { readLines } from "https://deno.land/std@0.85.0/io/mod.ts";
import { printQuestion } from "./mod";
export const getNumericInput = (): Promise<number> => Promise.resolve(4);
export async function getUserInput(): Promise<string> {
printQuestion("What would you like to enter");
const reader = readLines(Deno.stdin);
return (await reader.next()).value;
}

View File

@ -0,0 +1,3 @@
export function printQuestion(question: string): void {
console.log(question, "?????");
}

View File

@ -0,0 +1,5 @@
export * from "./ask_trivia";
export * from "./generate_source";
export * from "./get_user_input";
export * from "./logger";
export * from "./pick_trivia";

View File

@ -0,0 +1,8 @@
import { TRIVIA } from "../types/mod";
import { ALL_TRIVIA } from "../trivia/mod";
export function getFirstTrivia(
providedTrivia: TRIVIA[] = ALL_TRIVIA,
): TRIVIA {
return providedTrivia[0];
}

View File

@ -0,0 +1,5 @@
import { ALL_TRIVIA } from "./trivia/mod";
export default () => {
console.log("Number of Trivia Questions:", ALL_TRIVIA.length);
};

View File

@ -0,0 +1,11 @@
import { generateTVSource } from "../helpers/mod";
import { TRIVIA } from "../types/mod";
const trivia: TRIVIA[] = [{
question: "Where did episode 1 take place",
correctAnswer: "On a boat",
wrongAnswers: ["On a plane", "On a mountain", "On a beach"],
source: generateTVSource("A TV Show Episode 1"),
}];
export default trivia;

View File

@ -0,0 +1,4 @@
import { TRIVIA } from "../types/mod.ts";
import aTVShow from "./a_tv_show.ts";
export const ALL_TRIVIA: TRIVIA[] = [...aTVShow];

View File

@ -0,0 +1,11 @@
export interface SOURCE {
name: string;
mediaType: string;
}
export interface TRIVIA {
question: string;
correctAnswer: string;
wrongAnswers: [string, string, string];
source: SOURCE;
}

View File

@ -3549,92 +3549,6 @@ const mod = function() {
const Duration1 = Duration; const Duration1 = Duration;
const Duration2 = Duration; const Duration2 = Duration;
const Duration3 = Duration; const Duration3 = Duration;
function dayDiff(earlier, later) {
const utcDayStart = (dt)=>dt.toUTC(0, {
keepLocalTime: true
}).startOf("day").valueOf()
, ms = utcDayStart(later) - utcDayStart(earlier);
return Math.floor(Duration.fromMillis(ms).as("days"));
}
function highOrderDiffs(cursor, later, units) {
const differs = [
[
"years",
(a, b)=>b.year - a.year
],
[
"months",
(a, b)=>b.month - a.month + (b.year - a.year) * 12
],
[
"weeks",
(a, b)=>{
const days = dayDiff(a, b);
return (days - days % 7) / 7;
}
],
[
"days",
dayDiff
]
];
const results = {
};
let lowestOrder, highWater;
for (const [unit2, differ] of differs){
if (units.indexOf(unit2) >= 0) {
lowestOrder = unit2;
let delta = differ(cursor, later);
highWater = cursor.plus({
[unit2]: delta
});
if (highWater > later) {
cursor = cursor.plus({
[unit2]: delta - 1
});
delta -= 1;
} else {
cursor = highWater;
}
results[unit2] = delta;
}
}
return [
cursor,
results,
highWater,
lowestOrder
];
}
const __default12 = function(earlier, later, units, opts) {
let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units);
const remainingMillis = later - cursor;
const lowerOrderUnits = units.filter((u)=>[
"hours",
"minutes",
"seconds",
"milliseconds"
].indexOf(u) >= 0
);
if (lowerOrderUnits.length === 0) {
if (highWater < later) {
highWater = cursor.plus({
[lowestOrder]: 1
});
}
if (highWater !== cursor) {
results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor);
}
}
const duration = Duration.fromObject(Object.assign(results, opts));
if (lowerOrderUnits.length > 0) {
return Duration.fromMillis(remainingMillis, opts).shiftTo(...lowerOrderUnits).plus(duration);
} else {
return duration;
}
};
const __default13 = __default12;
const diff = __default12;
const Duration4 = Duration; const Duration4 = Duration;
const Duration5 = Duration; const Duration5 = Duration;
function friendlyDuration(durationish) { function friendlyDuration(durationish) {
@ -3715,8 +3629,8 @@ const mod = function() {
}; };
} }
} }
const __default14 = Info; const __default12 = Info;
const __default15 = Info; const __default13 = Info;
const Info1 = Info; const Info1 = Info;
const Info2 = Info; const Info2 = Info;
const Info3 = Info; const Info3 = Info;
@ -3761,8 +3675,8 @@ const mod = function() {
return true; return true;
} }
} }
const __default16 = LocalZone; const __default14 = LocalZone;
const __default17 = LocalZone; const __default15 = LocalZone;
const LocalZone1 = LocalZone; const LocalZone1 = LocalZone;
const LocalZone2 = LocalZone; const LocalZone2 = LocalZone;
const LocalZone3 = LocalZone; const LocalZone3 = LocalZone;
@ -3815,8 +3729,8 @@ const mod = function() {
IANAZone.resetCache(); IANAZone.resetCache();
} }
} }
const __default18 = Settings; const __default16 = Settings;
const __default19 = Settings; const __default17 = Settings;
const Settings1 = Settings; const Settings1 = Settings;
const Settings2 = Settings; const Settings2 = Settings;
const Settings3 = Settings; const Settings3 = Settings;
@ -4231,12 +4145,99 @@ const mod = function() {
return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar; return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
} }
} }
const __default20 = Locale; const __default18 = Locale;
const __default21 = Locale; const __default19 = Locale;
const Locale1 = Locale; const Locale1 = Locale;
const Locale2 = Locale; const Locale2 = Locale;
const Locale3 = Locale; const Locale3 = Locale;
const Locale4 = Locale; const Locale4 = Locale;
function dayDiff(earlier, later) {
const utcDayStart = (dt2)=>dt2.toUTC(0, {
keepLocalTime: true
}).startOf("day").valueOf()
, ms = utcDayStart(later) - utcDayStart(earlier);
return Math.floor(Duration.fromMillis(ms).as("days"));
}
function highOrderDiffs(cursor, later, units) {
const differs = [
[
"years",
(a, b)=>b.year - a.year
],
[
"months",
(a, b)=>b.month - a.month + (b.year - a.year) * 12
],
[
"weeks",
(a, b)=>{
const days = dayDiff(a, b);
return (days - days % 7) / 7;
}
],
[
"days",
dayDiff
]
];
const results = {
};
let lowestOrder, highWater;
for (const [unit2, differ] of differs){
if (units.indexOf(unit2) >= 0) {
lowestOrder = unit2;
let delta = differ(cursor, later);
highWater = cursor.plus({
[unit2]: delta
});
if (highWater > later) {
cursor = cursor.plus({
[unit2]: delta - 1
});
delta -= 1;
} else {
cursor = highWater;
}
results[unit2] = delta;
}
}
return [
cursor,
results,
highWater,
lowestOrder
];
}
function __default20(earlier, later, units, opts4) {
let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units);
const remainingMillis = later - cursor;
const lowerOrderUnits = units.filter((u)=>[
"hours",
"minutes",
"seconds",
"milliseconds"
].indexOf(u) >= 0
);
if (lowerOrderUnits.length === 0) {
if (highWater < later) {
highWater = cursor.plus({
[lowestOrder]: 1
});
}
if (highWater !== cursor) {
results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor);
}
}
const duration = Duration.fromObject(Object.assign(results, opts4));
if (lowerOrderUnits.length > 0) {
return Duration.fromMillis(remainingMillis, opts4).shiftTo(...lowerOrderUnits).plus(duration);
} else {
return duration;
}
}
const __default21 = __default20;
const __default22 = __default20;
const diff = __default20;
const numberingSystems = { const numberingSystems = {
arab: "[\u0660-\u0669]", arab: "[\u0660-\u0669]",
arabext: "[\u06F0-\u06F9]", arabext: "[\u06F0-\u06F9]",

View File

@ -3595,92 +3595,6 @@ const mod = function() {
const Duration1 = __default17; const Duration1 = __default17;
const Duration2 = Duration1; const Duration2 = Duration1;
const Duration3 = __default17; const Duration3 = __default17;
function dayDiff(earlier, later) {
const utcDayStart = (dt)=>dt.toUTC(0, {
keepLocalTime: true
}).startOf("day").valueOf()
, ms = utcDayStart(later) - utcDayStart(earlier);
return Math.floor(Duration3.fromMillis(ms).as("days"));
}
function highOrderDiffs(cursor, later, units) {
const differs = [
[
"years",
(a, b)=>b.year - a.year
],
[
"months",
(a, b)=>b.month - a.month + (b.year - a.year) * 12
],
[
"weeks",
(a, b)=>{
const days = dayDiff(a, b);
return (days - days % 7) / 7;
}
],
[
"days",
dayDiff
]
];
const results = {
};
let lowestOrder, highWater;
for (const [unit2, differ] of differs){
if (units.indexOf(unit2) >= 0) {
lowestOrder = unit2;
let delta = differ(cursor, later);
highWater = cursor.plus({
[unit2]: delta
});
if (highWater > later) {
cursor = cursor.plus({
[unit2]: delta - 1
});
delta -= 1;
} else {
cursor = highWater;
}
results[unit2] = delta;
}
}
return [
cursor,
results,
highWater,
lowestOrder
];
}
const __default18 = function(earlier, later, units, opts) {
let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units);
const remainingMillis = later - cursor;
const lowerOrderUnits = units.filter((u)=>[
"hours",
"minutes",
"seconds",
"milliseconds"
].indexOf(u) >= 0
);
if (lowerOrderUnits.length === 0) {
if (highWater < later) {
highWater = cursor.plus({
[lowestOrder]: 1
});
}
if (highWater !== cursor) {
results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor);
}
}
const duration = Duration3.fromObject(Object.assign(results, opts));
if (lowerOrderUnits.length > 0) {
return Duration3.fromMillis(remainingMillis, opts).shiftTo(...lowerOrderUnits).plus(duration);
} else {
return duration;
}
};
const __default19 = __default18;
const diff = __default19;
const Duration4 = __default17; const Duration4 = __default17;
const Duration5 = __default17; const Duration5 = __default17;
function friendlyDuration(durationish) { function friendlyDuration(durationish) {
@ -3761,11 +3675,11 @@ const mod = function() {
}; };
} }
} }
const __default20 = Info; const __default18 = Info;
const __default21 = __default20; const __default19 = __default18;
const Info1 = __default21; const Info1 = __default19;
const Info2 = Info1; const Info2 = Info1;
const Info3 = __default21; const Info3 = __default19;
let now = ()=>Date.now() let now = ()=>Date.now()
, defaultZone = null, defaultLocale = null, defaultNumberingSystem = null, defaultOutputCalendar = null, throwOnInvalid = false; , defaultZone = null, defaultLocale = null, defaultNumberingSystem = null, defaultOutputCalendar = null, throwOnInvalid = false;
const hasIntl3 = hasIntl1; const hasIntl3 = hasIntl1;
@ -3807,11 +3721,11 @@ const mod = function() {
return true; return true;
} }
} }
const __default22 = LocalZone; const __default20 = LocalZone;
const __default23 = __default22; const __default21 = __default20;
const LocalZone1 = __default23; const LocalZone1 = __default21;
const LocalZone2 = LocalZone1; const LocalZone2 = LocalZone1;
const LocalZone3 = __default23; const LocalZone3 = __default21;
class Settings { class Settings {
static get now() { static get now() {
return now; return now;
@ -3861,15 +3775,15 @@ const mod = function() {
IANAZone4.resetCache(); IANAZone4.resetCache();
} }
} }
const __default24 = Settings; const __default22 = Settings;
const __default25 = __default24; const __default23 = __default22;
const Settings1 = __default25; const Settings1 = __default23;
const Settings2 = Settings1; const Settings2 = Settings1;
const Settings3 = __default25; const Settings3 = __default23;
const Settings4 = __default25; const Settings4 = __default23;
const Settings5 = __default25; const Settings5 = __default23;
const Settings6 = __default25; const Settings6 = __default23;
const Settings7 = __default25; const Settings7 = __default23;
let intlDTCache = { let intlDTCache = {
}; };
function getCachedDTF(locString, opts = { function getCachedDTF(locString, opts = {
@ -4277,12 +4191,99 @@ const mod = function() {
return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar; return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
} }
} }
const __default26 = Locale; const __default24 = Locale;
const __default25 = __default24;
const Locale1 = __default25;
const Locale2 = __default25;
const Locale3 = __default25;
const Locale4 = __default25;
function dayDiff(earlier, later) {
const utcDayStart = (dt2)=>dt2.toUTC(0, {
keepLocalTime: true
}).startOf("day").valueOf()
, ms = utcDayStart(later) - utcDayStart(earlier);
return Math.floor(Duration3.fromMillis(ms).as("days"));
}
function highOrderDiffs(cursor, later, units) {
const differs = [
[
"years",
(a, b)=>b.year - a.year
],
[
"months",
(a, b)=>b.month - a.month + (b.year - a.year) * 12
],
[
"weeks",
(a, b)=>{
const days = dayDiff(a, b);
return (days - days % 7) / 7;
}
],
[
"days",
dayDiff
]
];
const results = {
};
let lowestOrder, highWater;
for (const [unit2, differ] of differs){
if (units.indexOf(unit2) >= 0) {
lowestOrder = unit2;
let delta = differ(cursor, later);
highWater = cursor.plus({
[unit2]: delta
});
if (highWater > later) {
cursor = cursor.plus({
[unit2]: delta - 1
});
delta -= 1;
} else {
cursor = highWater;
}
results[unit2] = delta;
}
}
return [
cursor,
results,
highWater,
lowestOrder
];
}
function __default26(earlier, later, units, opts4) {
let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units);
const remainingMillis = later - cursor;
const lowerOrderUnits = units.filter((u)=>[
"hours",
"minutes",
"seconds",
"milliseconds"
].indexOf(u) >= 0
);
if (lowerOrderUnits.length === 0) {
if (highWater < later) {
highWater = cursor.plus({
[lowestOrder]: 1
});
}
if (highWater !== cursor) {
results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor);
}
}
const duration = Duration3.fromObject(Object.assign(results, opts4));
if (lowerOrderUnits.length > 0) {
return Duration3.fromMillis(remainingMillis, opts4).shiftTo(...lowerOrderUnits).plus(duration);
} else {
return duration;
}
}
const __default27 = __default26; const __default27 = __default26;
const Locale1 = __default27; const __default28 = __default27;
const Locale2 = __default27; const diff = __default28;
const Locale3 = __default27;
const Locale4 = __default27;
const numberingSystems = { const numberingSystems = {
arab: "[\u0660-\u0669]", arab: "[\u0660-\u0669]",
arabext: "[\u06F0-\u06F9]", arabext: "[\u06F0-\u06F9]",

View File

@ -0,0 +1,7 @@
import log from "./log";
cli();
export default async function cli() {
log("It works!");
}

View File

@ -0,0 +1,3 @@
export default function (message) {
console.log(message);
}

View File

@ -0,0 +1,8 @@
function __default(message) {
console.log(message);
}
cli();
async function cli() {
__default("It works!");
}
export { cli as default };

View File

@ -0,0 +1,12 @@
function __default(message) {
console.log(message);
}
const __default1 = __default;
const __default2 = __default1;
const log = __default2;
cli();
async function cli() {
log("It works!");
}
const __default3 = cli;
export { __default3 as default };