diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml index e0f0e5c9bc34..c1cedf0bdad8 100644 --- a/.github/workflows/cargo.yml +++ b/.github/workflows/cargo.yml @@ -14,8 +14,6 @@ on: [push, pull_request] env: CARGO_INCREMENTAL: 0 - # To make spack tests reliable - RAYON_NUM_THREADS: 1 CI: "1" jobs: @@ -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 @@ -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 diff --git a/bundler/src/bundler/chunk/merge.rs b/bundler/src/bundler/chunk/merge.rs index c5dcdb6b3061..bd32f07f3a8a 100644 --- a/bundler/src/bundler/chunk/merge.rs +++ b/bundler/src/bundler/chunk/merge.rs @@ -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); @@ -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) { diff --git a/bundler/src/bundler/keywords.rs b/bundler/src/bundler/keywords.rs index ef7ec02e9eae..86704df7f3b9 100644 --- a/bundler/src/bundler/keywords.rs +++ b/bundler/src/bundler/keywords.rs @@ -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::*; @@ -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) { diff --git a/bundler/tests/deno-exec/.deno-9200/case1/entry.ts b/bundler/tests/deno-exec/.deno-9200/case1/entry.ts new file mode 100644 index 000000000000..bd1fa5168a72 --- /dev/null +++ b/bundler/tests/deno-exec/.deno-9200/case1/entry.ts @@ -0,0 +1,3 @@ +import { isEmail } from "https://deno.land/x/segno@v1.1.0/mod.ts"; + +isEmail("test@test.com"); diff --git a/bundler/tests/fixture/circular-imports/complex-export/output/entry.inlined.js b/bundler/tests/fixture/circular-imports/complex-export/output/entry.inlined.js index 8c7ff0cf7793..d49f517993c9 100644 --- a/bundler/tests/fixture/circular-imports/complex-export/output/entry.inlined.js +++ b/bundler/tests/fixture/circular-imports/complex-export/output/entry.inlined.js @@ -1,4 +1,5 @@ -const a1 = 'a'; +const a2 = 'a'; const c1 = 'c'; +const a1 = a2; export { a1 as a }; export { c1 as c }; diff --git a/bundler/tests/fixture/deno-8978/output/entry.inlined.ts b/bundler/tests/fixture/deno-8978/output/entry.inlined.ts index c0bc35044b42..683de512f69e 100644 --- a/bundler/tests/fixture/deno-8978/output/entry.inlined.ts +++ b/bundler/tests/fixture/deno-8978/output/entry.inlined.ts @@ -1,3 +1,4 @@ const f = ()=>"hello world" ; -export { f as any }; +const any1 = f; +export { any1 as any }; diff --git a/bundler/tests/fixture/deno-9055/keywords-1/input/entry.ts b/bundler/tests/fixture/deno-9055/keywords-1/input/entry.ts new file mode 100644 index 000000000000..dfbf73ce1276 --- /dev/null +++ b/bundler/tests/fixture/deno-9055/keywords-1/input/entry.ts @@ -0,0 +1,9 @@ +const x = { + n: 123, + t: 'text', + int: '==INT==' +} + +const { n, t, int } = x + +console.log(n, t, int) diff --git a/bundler/tests/fixture/deno-9055/keywords-1/output/entry.inlined.ts b/bundler/tests/fixture/deno-9055/keywords-1/output/entry.inlined.ts new file mode 100644 index 000000000000..23973b7103ea --- /dev/null +++ b/bundler/tests/fixture/deno-9055/keywords-1/output/entry.inlined.ts @@ -0,0 +1,7 @@ +const x = { + n: 123, + t: 'text', + int: '==INT==' +}; +const { n , t , int: __int } = x; +console.log(n, t, __int); diff --git a/bundler/tests/fixture/deno-9055/keywords-1/output/entry.ts b/bundler/tests/fixture/deno-9055/keywords-1/output/entry.ts new file mode 100644 index 000000000000..23973b7103ea --- /dev/null +++ b/bundler/tests/fixture/deno-9055/keywords-1/output/entry.ts @@ -0,0 +1,7 @@ +const x = { + n: 123, + t: 'text', + int: '==INT==' +}; +const { n , t , int: __int } = x; +console.log(n, t, __int); diff --git a/bundler/tests/fixture/deno-9055/keywords-2/input/entry.ts b/bundler/tests/fixture/deno-9055/keywords-2/input/entry.ts new file mode 100644 index 000000000000..07f1b369e19b --- /dev/null +++ b/bundler/tests/fixture/deno-9055/keywords-2/input/entry.ts @@ -0,0 +1,9 @@ +const x = { + n: 123, + t: 'text', + int: '==INT==' +} + +const { n, t, int = 5 } = x + +console.log(n, t, int) diff --git a/bundler/tests/fixture/deno-9055/keywords-2/output/entry.inlined.ts b/bundler/tests/fixture/deno-9055/keywords-2/output/entry.inlined.ts new file mode 100644 index 000000000000..ca042b7799a2 --- /dev/null +++ b/bundler/tests/fixture/deno-9055/keywords-2/output/entry.inlined.ts @@ -0,0 +1,7 @@ +const x = { + n: 123, + t: 'text', + int: '==INT==' +}; +const { n , t , int: __int = 5 } = x; +console.log(n, t, __int); diff --git a/bundler/tests/fixture/deno-9055/keywords-2/output/entry.ts b/bundler/tests/fixture/deno-9055/keywords-2/output/entry.ts new file mode 100644 index 000000000000..ca042b7799a2 --- /dev/null +++ b/bundler/tests/fixture/deno-9055/keywords-2/output/entry.ts @@ -0,0 +1,7 @@ +const x = { + n: 123, + t: 'text', + int: '==INT==' +}; +const { n , t , int: __int = 5 } = x; +console.log(n, t, __int); diff --git a/bundler/tests/fixture/deno-9176/test-2/output/entry.inlined.ts b/bundler/tests/fixture/deno-9176/test-2/output/entry.inlined.ts index 9b754ff81985..f0f41605518a 100644 --- a/bundler/tests/fixture/deno-9176/test-2/output/entry.inlined.ts +++ b/bundler/tests/fixture/deno-9176/test-2/output/entry.inlined.ts @@ -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 }; diff --git a/bundler/tests/fixture/deno-9200/.case1/input/deps.ts b/bundler/tests/fixture/deno-9200/.case1/input/deps.ts new file mode 100644 index 000000000000..56aa55a9ae2a --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case1/input/deps.ts @@ -0,0 +1,7 @@ +import * as lib from './lib'; + +// exporting all functions +export * from './lib'; + +// exporting functions namespaced to segno +export { lib }; \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9200/.case1/input/entry.ts b/bundler/tests/fixture/deno-9200/.case1/input/entry.ts new file mode 100644 index 000000000000..4f2c3d5e2bd5 --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case1/input/entry.ts @@ -0,0 +1,2 @@ +import { foo } from './deps' +foo() \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9200/.case1/input/lib-impl1.ts b/bundler/tests/fixture/deno-9200/.case1/input/lib-impl1.ts new file mode 100644 index 000000000000..be5ce679829a --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case1/input/lib-impl1.ts @@ -0,0 +1 @@ +export function foo() { } \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9200/.case1/input/lib.ts b/bundler/tests/fixture/deno-9200/.case1/input/lib.ts new file mode 100644 index 000000000000..4cf127740543 --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case1/input/lib.ts @@ -0,0 +1 @@ +export * from './lib-impl1' \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9200/.case2/input/entry.ts b/bundler/tests/fixture/deno-9200/.case2/input/entry.ts new file mode 100644 index 000000000000..56aa55a9ae2a --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case2/input/entry.ts @@ -0,0 +1,7 @@ +import * as lib from './lib'; + +// exporting all functions +export * from './lib'; + +// exporting functions namespaced to segno +export { lib }; \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9200/.case2/input/lib-impl1.ts b/bundler/tests/fixture/deno-9200/.case2/input/lib-impl1.ts new file mode 100644 index 000000000000..be5ce679829a --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case2/input/lib-impl1.ts @@ -0,0 +1 @@ +export function foo() { } \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9200/.case2/input/lib.ts b/bundler/tests/fixture/deno-9200/.case2/input/lib.ts new file mode 100644 index 000000000000..4cf127740543 --- /dev/null +++ b/bundler/tests/fixture/deno-9200/.case2/input/lib.ts @@ -0,0 +1 @@ +export * from './lib-impl1' \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9212/.case1/input/entry.ts b/bundler/tests/fixture/deno-9212/.case1/input/entry.ts new file mode 100644 index 000000000000..c4fc4a67bcd6 --- /dev/null +++ b/bundler/tests/fixture/deno-9212/.case1/input/entry.ts @@ -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) \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9219/case1/input/entry.ts b/bundler/tests/fixture/deno-9219/case1/input/entry.ts new file mode 100644 index 000000000000..d312f555bc16 --- /dev/null +++ b/bundler/tests/fixture/deno-9219/case1/input/entry.ts @@ -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); \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9219/case1/output/entry.inlined.ts b/bundler/tests/fixture/deno-9219/case1/output/entry.inlined.ts new file mode 100644 index 000000000000..b966a7164018 --- /dev/null +++ b/bundler/tests/fixture/deno-9219/case1/output/entry.inlined.ts @@ -0,0 +1,261 @@ +class DenoStdInternalError extends Error { + constructor(message){ + super(message); + this.name = "DenoStdInternalError"; + } +} +function assert(expr, msg = "") { + if (!expr) { + throw new DenoStdInternalError(msg); + } +} +function get(obj, key) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + return obj[key]; + } +} +function getForce(obj, key) { + const v = get(obj, key); + assert(v != null); + return v; +} +function isNumber(x) { + if (typeof x === "number") return true; + if (/^0x[0-9a-f]+$/i.test(String(x))) return true; + return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(String(x)); +} +function hasKey(obj, keys) { + let o = obj; + keys.slice(0, -1).forEach((key)=>{ + o = get(o, key) ?? { + }; + }); + const key = keys[keys.length - 1]; + return key in o; +} +function parse(args, { "--": doubleDash = false , alias ={ +} , boolean: __boolean = false , default: defaults = { +} , stopEarly =false , string =[] , unknown =(i)=>i + } = { +}) { + const flags = { + bools: { + }, + strings: { + }, + unknownFn: unknown, + allBools: false + }; + if (__boolean !== undefined) { + if (typeof __boolean === "boolean") { + flags.allBools = !!__boolean; + } else { + const booleanArgs = typeof __boolean === "string" ? [ + __boolean + ] : __boolean; + for (const key of booleanArgs.filter(Boolean)){ + flags.bools[key] = true; + } + } + } + const aliases = { + }; + if (alias !== undefined) { + for(const key in alias){ + const val = getForce(alias, key); + if (typeof val === "string") { + aliases[key] = [ + val + ]; + } else { + aliases[key] = val; + } + for (const alias1 of getForce(aliases, key)){ + aliases[alias1] = [ + key + ].concat(aliases[key].filter((y)=>alias1 !== y + )); + } + } + } + if (string !== undefined) { + const stringArgs = typeof string === "string" ? [ + string + ] : string; + for (const key of stringArgs.filter(Boolean)){ + flags.strings[key] = true; + const alias1 = get(aliases, key); + if (alias1) { + for (const al of alias1){ + flags.strings[al] = true; + } + } + } + } + const argv = { + _: [] + }; + function argDefined(key, arg) { + return flags.allBools && /^--[^=]+$/.test(arg) || get(flags.bools, key) || !!get(flags.strings, key) || !!get(aliases, key); + } + function setKey(obj, keys, value) { + let o = obj; + keys.slice(0, -1).forEach(function(key) { + if (get(o, key) === undefined) { + o[key] = { + }; + } + o = get(o, key); + }); + const key = keys[keys.length - 1]; + if (get(o, key) === undefined || get(flags.bools, key) || typeof get(o, key) === "boolean") { + o[key] = value; + } else if (Array.isArray(get(o, key))) { + o[key].push(value); + } else { + o[key] = [ + get(o, key), + value + ]; + } + } + function setArg(key, val, arg = undefined) { + if (arg && flags.unknownFn && !argDefined(key, arg)) { + if (flags.unknownFn(arg, key, val) === false) return; + } + const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val; + setKey(argv, key.split("."), value); + const alias1 = get(aliases, key); + if (alias1) { + for (const x of alias1){ + setKey(argv, x.split("."), value); + } + } + } + function aliasIsBoolean(key) { + return getForce(aliases, key).some((x)=>typeof get(flags.bools, x) === "boolean" + ); + } + for (const key of Object.keys(flags.bools)){ + setArg(key, defaults[key] === undefined ? false : defaults[key]); + } + let notFlags = []; + if (args.includes("--")) { + notFlags = args.slice(args.indexOf("--") + 1); + args = args.slice(0, args.indexOf("--")); + } + for(let i = 0; i < args.length; i++){ + const arg = args[i]; + if (/^--.+=/.test(arg)) { + const m = arg.match(/^--([^=]+)=(.*)$/s); + assert(m != null); + const [, key1, value] = m; + if (flags.bools[key1]) { + const booleanValue = value !== "false"; + setArg(key1, booleanValue, arg); + } else { + setArg(key1, value, arg); + } + } else if (/^--no-.+/.test(arg)) { + const m = arg.match(/^--no-(.+)/); + assert(m != null); + setArg(m[1], false, arg); + } else if (/^--.+/.test(arg)) { + const m = arg.match(/^--(.+)/); + assert(m != null); + const [, key1] = m; + const next = args[i + 1]; + if (next !== undefined && !/^-/.test(next) && !get(flags.bools, key1) && !flags.allBools && (get(aliases, key1) ? !aliasIsBoolean(key1) : true)) { + setArg(key1, next, arg); + i++; + } else if (/^(true|false)$/.test(next)) { + setArg(key1, next === "true", arg); + i++; + } else { + setArg(key1, get(flags.strings, key1) ? "" : true, arg); + } + } else if (/^-[^-]+/.test(arg)) { + const letters = arg.slice(1, -1).split(""); + let broken = false; + for(let j = 0; j < letters.length; j++){ + const next = arg.slice(j + 2); + if (next === "-") { + setArg(letters[j], next, arg); + continue; + } + if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) { + setArg(letters[j], next.split(/=(.+)/)[1], arg); + broken = true; + break; + } + if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) { + setArg(letters[j], next, arg); + broken = true; + break; + } + if (letters[j + 1] && letters[j + 1].match(/\W/)) { + setArg(letters[j], arg.slice(j + 2), arg); + broken = true; + break; + } else { + setArg(letters[j], get(flags.strings, letters[j]) ? "" : true, arg); + } + } + const [key1] = arg.slice(-1); + if (!broken && key1 !== "-") { + if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !get(flags.bools, key1) && (get(aliases, key1) ? !aliasIsBoolean(key1) : true)) { + setArg(key1, args[i + 1], arg); + i++; + } else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) { + setArg(key1, args[i + 1] === "true", arg); + i++; + } else { + setArg(key1, get(flags.strings, key1) ? "" : true, arg); + } + } + } else { + if (!flags.unknownFn || flags.unknownFn(arg) !== false) { + argv._.push(flags.strings["_"] ?? !isNumber(arg) ? arg : Number(arg)); + } + if (stopEarly) { + argv._.push(...args.slice(i + 1)); + break; + } + } + } + for (const key1 of Object.keys(defaults)){ + if (!hasKey(argv, key1.split("."))) { + setKey(argv, key1.split("."), defaults[key1]); + if (aliases[key1]) { + for (const x of aliases[key1]){ + setKey(argv, x.split("."), defaults[key1]); + } + } + } + } + if (doubleDash) { + argv["--"] = []; + for (const key2 of notFlags){ + argv["--"].push(key2); + } + } else { + for (const key2 of notFlags){ + argv._.push(key2); + } + } + return argv; +} +const args = parse(Deno.args, { + boolean: [ + "help", + "verbose", + ], + alias: { + help: "h", + verbose: "v" + }, + default: { + verbose: false + } +}); +console.dir(args); diff --git a/bundler/tests/fixture/deno-9219/case1/output/entry.ts b/bundler/tests/fixture/deno-9219/case1/output/entry.ts new file mode 100644 index 000000000000..2c3d92d28a23 --- /dev/null +++ b/bundler/tests/fixture/deno-9219/case1/output/entry.ts @@ -0,0 +1,265 @@ +class DenoStdInternalError extends Error { + constructor(message){ + super(message); + this.name = "DenoStdInternalError"; + } +} +function assert(expr, msg = "") { + if (!expr) { + throw new DenoStdInternalError(msg); + } +} +const assert1 = assert; +const assert2 = assert1; +function get(obj, key) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + return obj[key]; + } +} +function getForce(obj, key) { + const v = get(obj, key); + assert2(v != null); + return v; +} +function isNumber(x) { + if (typeof x === "number") return true; + if (/^0x[0-9a-f]+$/i.test(String(x))) return true; + return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(String(x)); +} +function hasKey(obj, keys) { + let o = obj; + keys.slice(0, -1).forEach((key)=>{ + o = get(o, key) ?? { + }; + }); + const key = keys[keys.length - 1]; + return key in o; +} +function parse(args, { "--": doubleDash = false , alias ={ +} , boolean: __boolean = false , default: defaults = { +} , stopEarly =false , string =[] , unknown =(i)=>i + } = { +}) { + const flags = { + bools: { + }, + strings: { + }, + unknownFn: unknown, + allBools: false + }; + if (__boolean !== undefined) { + if (typeof __boolean === "boolean") { + flags.allBools = !!__boolean; + } else { + const booleanArgs = typeof __boolean === "string" ? [ + __boolean + ] : __boolean; + for (const key of booleanArgs.filter(Boolean)){ + flags.bools[key] = true; + } + } + } + const aliases = { + }; + if (alias !== undefined) { + for(const key in alias){ + const val = getForce(alias, key); + if (typeof val === "string") { + aliases[key] = [ + val + ]; + } else { + aliases[key] = val; + } + for (const alias1 of getForce(aliases, key)){ + aliases[alias1] = [ + key + ].concat(aliases[key].filter((y)=>alias1 !== y + )); + } + } + } + if (string !== undefined) { + const stringArgs = typeof string === "string" ? [ + string + ] : string; + for (const key of stringArgs.filter(Boolean)){ + flags.strings[key] = true; + const alias1 = get(aliases, key); + if (alias1) { + for (const al of alias1){ + flags.strings[al] = true; + } + } + } + } + const argv = { + _: [] + }; + function argDefined(key, arg) { + return flags.allBools && /^--[^=]+$/.test(arg) || get(flags.bools, key) || !!get(flags.strings, key) || !!get(aliases, key); + } + function setKey(obj, keys, value) { + let o = obj; + keys.slice(0, -1).forEach(function(key) { + if (get(o, key) === undefined) { + o[key] = { + }; + } + o = get(o, key); + }); + const key = keys[keys.length - 1]; + if (get(o, key) === undefined || get(flags.bools, key) || typeof get(o, key) === "boolean") { + o[key] = value; + } else if (Array.isArray(get(o, key))) { + o[key].push(value); + } else { + o[key] = [ + get(o, key), + value + ]; + } + } + function setArg(key, val, arg = undefined) { + if (arg && flags.unknownFn && !argDefined(key, arg)) { + if (flags.unknownFn(arg, key, val) === false) return; + } + const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val; + setKey(argv, key.split("."), value); + const alias1 = get(aliases, key); + if (alias1) { + for (const x of alias1){ + setKey(argv, x.split("."), value); + } + } + } + function aliasIsBoolean(key) { + return getForce(aliases, key).some((x)=>typeof get(flags.bools, x) === "boolean" + ); + } + for (const key of Object.keys(flags.bools)){ + setArg(key, defaults[key] === undefined ? false : defaults[key]); + } + let notFlags = []; + if (args.includes("--")) { + notFlags = args.slice(args.indexOf("--") + 1); + args = args.slice(0, args.indexOf("--")); + } + for(let i = 0; i < args.length; i++){ + const arg = args[i]; + if (/^--.+=/.test(arg)) { + const m = arg.match(/^--([^=]+)=(.*)$/s); + assert2(m != null); + const [, key1, value] = m; + if (flags.bools[key1]) { + const booleanValue = value !== "false"; + setArg(key1, booleanValue, arg); + } else { + setArg(key1, value, arg); + } + } else if (/^--no-.+/.test(arg)) { + const m = arg.match(/^--no-(.+)/); + assert2(m != null); + setArg(m[1], false, arg); + } else if (/^--.+/.test(arg)) { + const m = arg.match(/^--(.+)/); + assert2(m != null); + const [, key1] = m; + const next = args[i + 1]; + if (next !== undefined && !/^-/.test(next) && !get(flags.bools, key1) && !flags.allBools && (get(aliases, key1) ? !aliasIsBoolean(key1) : true)) { + setArg(key1, next, arg); + i++; + } else if (/^(true|false)$/.test(next)) { + setArg(key1, next === "true", arg); + i++; + } else { + setArg(key1, get(flags.strings, key1) ? "" : true, arg); + } + } else if (/^-[^-]+/.test(arg)) { + const letters = arg.slice(1, -1).split(""); + let broken = false; + for(let j = 0; j < letters.length; j++){ + const next = arg.slice(j + 2); + if (next === "-") { + setArg(letters[j], next, arg); + continue; + } + if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) { + setArg(letters[j], next.split(/=(.+)/)[1], arg); + broken = true; + break; + } + if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) { + setArg(letters[j], next, arg); + broken = true; + break; + } + if (letters[j + 1] && letters[j + 1].match(/\W/)) { + setArg(letters[j], arg.slice(j + 2), arg); + broken = true; + break; + } else { + setArg(letters[j], get(flags.strings, letters[j]) ? "" : true, arg); + } + } + const [key1] = arg.slice(-1); + if (!broken && key1 !== "-") { + if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !get(flags.bools, key1) && (get(aliases, key1) ? !aliasIsBoolean(key1) : true)) { + setArg(key1, args[i + 1], arg); + i++; + } else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) { + setArg(key1, args[i + 1] === "true", arg); + i++; + } else { + setArg(key1, get(flags.strings, key1) ? "" : true, arg); + } + } + } else { + if (!flags.unknownFn || flags.unknownFn(arg) !== false) { + argv._.push(flags.strings["_"] ?? !isNumber(arg) ? arg : Number(arg)); + } + if (stopEarly) { + argv._.push(...args.slice(i + 1)); + break; + } + } + } + for (const key1 of Object.keys(defaults)){ + if (!hasKey(argv, key1.split("."))) { + setKey(argv, key1.split("."), defaults[key1]); + if (aliases[key1]) { + for (const x of aliases[key1]){ + setKey(argv, x.split("."), defaults[key1]); + } + } + } + } + if (doubleDash) { + argv["--"] = []; + for (const key2 of notFlags){ + argv["--"].push(key2); + } + } else { + for (const key2 of notFlags){ + argv._.push(key2); + } + } + return argv; +} +const parse1 = parse; +const parse2 = parse1; +const args = parse2(Deno.args, { + boolean: [ + "help", + "verbose", + ], + alias: { + help: "h", + verbose: "v" + }, + default: { + verbose: false + } +}); +console.dir(args); diff --git a/bundler/tests/fixture/deno-9220/case1/input/entry.ts b/bundler/tests/fixture/deno-9220/case1/input/entry.ts new file mode 100644 index 000000000000..3af27629b182 --- /dev/null +++ b/bundler/tests/fixture/deno-9220/case1/input/entry.ts @@ -0,0 +1 @@ +export * from 'https://deno.land/x/jpegts@1.1/lib/decoder.ts'; \ No newline at end of file diff --git a/bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts b/bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts new file mode 100644 index 000000000000..1ed856c2d9b3 --- /dev/null +++ b/bundler/tests/fixture/deno-9220/case1/output/entry.inlined.ts @@ -0,0 +1,960 @@ +const JpegImage = function jpegImage() { + "use strict"; + const dctZigZag = new Int32Array([ + 0, + 1, + 8, + 16, + 9, + 2, + 3, + 10, + 17, + 24, + 32, + 25, + 18, + 11, + 4, + 5, + 12, + 19, + 26, + 33, + 40, + 48, + 41, + 34, + 27, + 20, + 13, + 6, + 7, + 14, + 21, + 28, + 35, + 42, + 49, + 56, + 57, + 50, + 43, + 36, + 29, + 22, + 15, + 23, + 30, + 37, + 44, + 51, + 58, + 59, + 52, + 45, + 38, + 31, + 39, + 46, + 53, + 60, + 61, + 54, + 47, + 55, + 62, + 63 + ]); + const dctCos1 = 4017; + const dctSin1 = 799; + const dctCos3 = 3406; + const dctSin3 = 2276; + const dctCos6 = 1567; + const dctSin6 = 3784; + const dctSqrt2 = 5793; + const dctSqrt1d2 = 2896; + function constructor() { + } + function buildHuffmanTable(codeLengths, values) { + let k = 0; + const code = []; + let i, j, length = 16; + while(length > 0 && !codeLengths[length - 1]){ + length--; + } + code.push({ + children: [], + index: 0 + }); + let p = code[0], q; + for(i = 0; i < length; i++){ + for(j = 0; j < codeLengths[i]; j++){ + p = code.pop(); + p.children[p.index] = values[k]; + while(p.index > 0){ + p = code.pop(); + } + p.index++; + code.push(p); + while(code.length <= i){ + code.push(q = { + children: [], + index: 0 + }); + p.children[p.index] = q.children; + p = q; + } + k++; + } + if (i + 1 < length) { + code.push(q = { + children: [], + index: 0 + }); + p.children[p.index] = q.children; + p = q; + } + } + return code[0].children; + } + function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) { + const mcusPerLine = frame.mcusPerLine; + const progressive = frame.progressive; + const startOffset = offset; + let bitsData = 0, bitsCount = 0; + function readBit() { + if (bitsCount > 0) { + bitsCount--; + return bitsData >> bitsCount & 1; + } + bitsData = data[offset++]; + if (bitsData === 255) { + const nextByte = data[offset++]; + if (nextByte) { + throw new Error("unexpected marker: " + (bitsData << 8 | nextByte).toString(16)); + } + } + bitsCount = 7; + return bitsData >>> 7; + } + function decodeHuffman(tree) { + let node = tree, bit; + while((bit = readBit()) !== null){ + node = node[bit]; + if (typeof node === "number") { + return node; + } + if (typeof node !== "object") { + throw new Error("invalid huffman sequence"); + } + } + return null; + } + function receive(length) { + let n = 0; + while(length > 0){ + const bit = readBit(); + if (bit === null) { + return; + } + n = n << 1 | bit; + length--; + } + return n; + } + function receiveAndExtend(length) { + const n = receive(length); + if (n >= 1 << length - 1) { + return n; + } + return n + (-1 << length) + 1; + } + function decodeBaseline(component, zz) { + const t = decodeHuffman(component.huffmanTableDC); + const diff = t === 0 ? 0 : receiveAndExtend(t); + zz[0] = component.pred += diff; + let k = 1; + while(k < 64){ + const rs = decodeHuffman(component.huffmanTableAC); + const s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + break; + } + k += 16; + continue; + } + k += r; + const z = dctZigZag[k]; + zz[z] = receiveAndExtend(s); + k++; + } + } + function decodeDCFirst(component, zz) { + const t = decodeHuffman(component.huffmanTableDC); + const diff = t === 0 ? 0 : receiveAndExtend(t) << successive; + zz[0] = component.pred += diff; + } + function decodeDCSuccessive(component, zz) { + zz[0] |= readBit() << successive; + } + let eobrun = 0; + function decodeACFirst(component, zz) { + if (eobrun > 0) { + eobrun--; + return; + } + let k = spectralStart, e = spectralEnd; + while(k <= e){ + const rs = decodeHuffman(component.huffmanTableAC); + const s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r) - 1; + break; + } + k += 16; + continue; + } + k += r; + const z = dctZigZag[k]; + zz[z] = receiveAndExtend(s) * (1 << successive); + k++; + } + } + let successiveACState = 0, successiveACNextValue; + function decodeACSuccessive(component, zz) { + let k = spectralStart, e = spectralEnd, r = 0; + while(k <= e){ + const z = dctZigZag[k]; + const direction = zz[z] < 0 ? -1 : 1; + switch(successiveACState){ + case 0: + const rs = decodeHuffman(component.huffmanTableAC); + const s = rs & 15; + r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r); + successiveACState = 4; + } else { + r = 16; + successiveACState = 1; + } + } else { + if (s !== 1) { + throw new Error("invalid ACn encoding"); + } + successiveACNextValue = receiveAndExtend(s); + successiveACState = r ? 2 : 3; + } + continue; + case 1: + case 2: + if (zz[z]) { + zz[z] += (readBit() << successive) * direction; + } else { + r--; + if (r === 0) { + successiveACState = successiveACState == 2 ? 3 : 0; + } + } + break; + case 3: + if (zz[z]) { + zz[z] += (readBit() << successive) * direction; + } else { + zz[z] = successiveACNextValue << successive; + successiveACState = 0; + } + break; + case 4: + if (zz[z]) { + zz[z] += (readBit() << successive) * direction; + } + break; + } + k++; + } + if (successiveACState === 4) { + eobrun--; + if (eobrun === 0) { + successiveACState = 0; + } + } + } + function decodeMcu(component, decode, mcu, row, col) { + const mcuRow = mcu / mcusPerLine | 0; + const mcuCol = mcu % mcusPerLine; + const blockRow = mcuRow * component.v + row; + const blockCol = mcuCol * component.h + col; + decode(component, component.blocks[blockRow][blockCol]); + } + function decodeBlock(component, decode, mcu) { + const blockRow = mcu / component.blocksPerLine | 0; + const blockCol = mcu % component.blocksPerLine; + decode(component, component.blocks[blockRow][blockCol]); + } + const componentsLength = components.length; + let component, i, j, k, n; + let decodeFn; + if (progressive) { + if (spectralStart === 0) { + decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; + } else { + decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; + } + } else { + decodeFn = decodeBaseline; + } + let mcu = 0, marker; + let mcuExpected; + if (componentsLength == 1) { + mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; + } else { + mcuExpected = mcusPerLine * frame.mcusPerColumn; + } + if (!resetInterval) { + resetInterval = mcuExpected; + } + let h, v; + while(mcu < mcuExpected){ + for(i = 0; i < componentsLength; i++){ + components[i].pred = 0; + } + eobrun = 0; + if (componentsLength == 1) { + component = components[0]; + for(n = 0; n < resetInterval; n++){ + decodeBlock(component, decodeFn, mcu); + mcu++; + } + } else { + for(n = 0; n < resetInterval; n++){ + for(i = 0; i < componentsLength; i++){ + component = components[i]; + h = component.h; + v = component.v; + for(j = 0; j < v; j++){ + for(k = 0; k < h; k++){ + decodeMcu(component, decodeFn, mcu, j, k); + } + } + } + mcu++; + if (mcu === mcuExpected) { + break; + } + } + } + bitsCount = 0; + marker = data[offset] << 8 | data[offset + 1]; + if (marker < 65280) { + throw new Error("marker was not found"); + } + if (marker >= 65488 && marker <= 65495) { + offset += 2; + } else { + break; + } + } + return offset - startOffset; + } + function buildComponentData(frame, component) { + const lines = []; + const blocksPerLine = component.blocksPerLine; + const blocksPerColumn = component.blocksPerColumn; + const samplesPerLine = blocksPerLine << 3; + const R = new Int32Array(64), r = new Uint8Array(64); + function quantizeAndInverse(zz, dataOut, dataIn) { + const qt = component.quantizationTable; + let v0, v1, v2, v3, v4, v5, v6, v7, t; + const p = dataIn; + let i; + for(i = 0; i < 64; i++){ + p[i] = zz[i] * qt[i]; + } + for(i = 0; i < 8; ++i){ + const row = 8 * i; + if (p[1 + row] == 0 && p[2 + row] == 0 && p[3 + row] == 0 && p[4 + row] == 0 && p[5 + row] == 0 && p[6 + row] == 0 && p[7 + row] == 0) { + t = dctSqrt2 * p[0 + row] + 512 >> 10; + p[0 + row] = t; + p[1 + row] = t; + p[2 + row] = t; + p[3 + row] = t; + p[4 + row] = t; + p[5 + row] = t; + p[6 + row] = t; + p[7 + row] = t; + continue; + } + v0 = dctSqrt2 * p[0 + row] + 128 >> 8; + v1 = dctSqrt2 * p[4 + row] + 128 >> 8; + v2 = p[2 + row]; + v3 = p[6 + row]; + v4 = dctSqrt1d2 * (p[1 + row] - p[7 + row]) + 128 >> 8; + v7 = dctSqrt1d2 * (p[1 + row] + p[7 + row]) + 128 >> 8; + v5 = p[3 + row] << 4; + v6 = p[5 + row] << 4; + t = v0 - v1 + 1 >> 1; + v0 = v0 + v1 + 1 >> 1; + v1 = t; + t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8; + v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8; + v3 = t; + t = v4 - v6 + 1 >> 1; + v4 = v4 + v6 + 1 >> 1; + v6 = t; + t = v7 + v5 + 1 >> 1; + v5 = v7 - v5 + 1 >> 1; + v7 = t; + t = v0 - v3 + 1 >> 1; + v0 = v0 + v3 + 1 >> 1; + v3 = t; + t = v1 - v2 + 1 >> 1; + v1 = v1 + v2 + 1 >> 1; + v2 = t; + t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; + v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; + v7 = t; + t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; + v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; + v6 = t; + p[0 + row] = v0 + v7; + p[7 + row] = v0 - v7; + p[1 + row] = v1 + v6; + p[6 + row] = v1 - v6; + p[2 + row] = v2 + v5; + p[5 + row] = v2 - v5; + p[3 + row] = v3 + v4; + p[4 + row] = v3 - v4; + } + for(i = 0; i < 8; ++i){ + const col = i; + if (p[1 * 8 + col] == 0 && p[2 * 8 + col] == 0 && p[3 * 8 + col] == 0 && p[4 * 8 + col] == 0 && p[5 * 8 + col] == 0 && p[6 * 8 + col] == 0 && p[7 * 8 + col] == 0) { + t = dctSqrt2 * dataIn[i + 0] + 8192 >> 14; + p[0 * 8 + col] = t; + p[1 * 8 + col] = t; + p[2 * 8 + col] = t; + p[3 * 8 + col] = t; + p[4 * 8 + col] = t; + p[5 * 8 + col] = t; + p[6 * 8 + col] = t; + p[7 * 8 + col] = t; + continue; + } + v0 = dctSqrt2 * p[0 * 8 + col] + 2048 >> 12; + v1 = dctSqrt2 * p[4 * 8 + col] + 2048 >> 12; + v2 = p[2 * 8 + col]; + v3 = p[6 * 8 + col]; + v4 = dctSqrt1d2 * (p[1 * 8 + col] - p[7 * 8 + col]) + 2048 >> 12; + v7 = dctSqrt1d2 * (p[1 * 8 + col] + p[7 * 8 + col]) + 2048 >> 12; + v5 = p[3 * 8 + col]; + v6 = p[5 * 8 + col]; + t = v0 - v1 + 1 >> 1; + v0 = v0 + v1 + 1 >> 1; + v1 = t; + t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12; + v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12; + v3 = t; + t = v4 - v6 + 1 >> 1; + v4 = v4 + v6 + 1 >> 1; + v6 = t; + t = v7 + v5 + 1 >> 1; + v5 = v7 - v5 + 1 >> 1; + v7 = t; + t = v0 - v3 + 1 >> 1; + v0 = v0 + v3 + 1 >> 1; + v3 = t; + t = v1 - v2 + 1 >> 1; + v1 = v1 + v2 + 1 >> 1; + v2 = t; + t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; + v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; + v7 = t; + t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; + v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; + v6 = t; + p[0 * 8 + col] = v0 + v7; + p[7 * 8 + col] = v0 - v7; + p[1 * 8 + col] = v1 + v6; + p[6 * 8 + col] = v1 - v6; + p[2 * 8 + col] = v2 + v5; + p[5 * 8 + col] = v2 - v5; + p[3 * 8 + col] = v3 + v4; + p[4 * 8 + col] = v3 - v4; + } + for(i = 0; i < 64; ++i){ + const sample = 128 + (p[i] + 8 >> 4); + dataOut[i] = sample < 0 ? 0 : sample > 255 ? 255 : sample; + } + } + let i, j; + for(let blockRow = 0; blockRow < blocksPerColumn; blockRow++){ + const scanLine = blockRow << 3; + for(i = 0; i < 8; i++){ + lines.push(new Uint8Array(samplesPerLine)); + } + for(let blockCol = 0; blockCol < blocksPerLine; blockCol++){ + quantizeAndInverse(component.blocks[blockRow][blockCol], r, R); + let offset = 0, sample = blockCol << 3; + for(j = 0; j < 8; j++){ + const line = lines[scanLine + j]; + for(i = 0; i < 8; i++){ + line[sample + i] = r[offset++]; + } + } + } + } + return lines; + } + function clampTo8bit(a) { + return a < 0 ? 0 : a > 255 ? 255 : a; + } + constructor.prototype = { + load: function load(path) { + }, + parse: function parse(data) { + let offset = 0; + function readUint16() { + const value = data[offset] << 8 | data[offset + 1]; + offset += 2; + return value; + } + function readDataBlock() { + const length = readUint16(); + const array = data.subarray(offset, offset + length - 2); + offset += array.length; + return array; + } + function prepareComponents(frame) { + let maxH = 0, maxV = 0; + let component, componentId; + for(componentId in frame.components){ + if (frame.components.hasOwnProperty(componentId)) { + component = frame.components[componentId]; + if (maxH < component.h) { + maxH = component.h; + } + if (maxV < component.v) { + maxV = component.v; + } + } + } + const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / maxH); + const mcusPerColumn = Math.ceil(frame.scanLines / 8 / maxV); + for(componentId in frame.components){ + if (frame.components.hasOwnProperty(componentId)) { + component = frame.components[componentId]; + const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / maxH); + const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / maxV); + const blocksPerLineForMcu = mcusPerLine * component.h; + const blocksPerColumnForMcu = mcusPerColumn * component.v; + const blocks = []; + for(let i = 0; i < blocksPerColumnForMcu; i++){ + const row = []; + for(let j = 0; j < blocksPerLineForMcu; j++){ + row.push(new Int32Array(64)); + } + blocks.push(row); + } + component.blocksPerLine = blocksPerLine; + component.blocksPerColumn = blocksPerColumn; + component.blocks = blocks; + } + } + frame.maxH = maxH; + frame.maxV = maxV; + frame.mcusPerLine = mcusPerLine; + frame.mcusPerColumn = mcusPerColumn; + } + let jfif = null; + let adobe = null; + let frame, resetInterval; + const quantizationTables = [], frames = []; + const huffmanTablesAC = [], huffmanTablesDC = []; + let fileMarker = readUint16(); + if (fileMarker != 65496) { + throw new Error("SOI not found"); + } + fileMarker = readUint16(); + while(fileMarker != 65497){ + let i, j, l; + switch(fileMarker){ + case 65280: break; + case 65504: + case 65505: + case 65506: + case 65507: + case 65508: + case 65509: + case 65510: + case 65511: + case 65512: + case 65513: + case 65514: + case 65515: + case 65516: + case 65517: + case 65518: + case 65519: + case 65534: + const appData = readDataBlock(); + if (fileMarker === 65504) { + if (appData[0] === 74 && appData[1] === 70 && appData[2] === 73 && appData[3] === 70 && appData[4] === 0) { + jfif = { + version: { + major: appData[5], + minor: appData[6] + }, + densityUnits: appData[7], + xDensity: appData[8] << 8 | appData[9], + yDensity: appData[10] << 8 | appData[11], + thumbWidth: appData[12], + thumbHeight: appData[13], + thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13]) + }; + } + } + if (fileMarker === 65518) { + if (appData[0] === 65 && appData[1] === 100 && appData[2] === 111 && appData[3] === 98 && appData[4] === 101 && appData[5] === 0) { + adobe = { + version: appData[6], + flags0: appData[7] << 8 | appData[8], + flags1: appData[9] << 8 | appData[10], + transformCode: appData[11] + }; + } + } + break; + case 65499: + const quantizationTablesLength = readUint16(); + const quantizationTablesEnd = quantizationTablesLength + offset - 2; + while(offset < quantizationTablesEnd){ + const quantizationTableSpec = data[offset++]; + const tableData = new Int32Array(64); + if (quantizationTableSpec >> 4 === 0) { + for(j = 0; j < 64; j++){ + const z = dctZigZag[j]; + tableData[z] = data[offset++]; + } + } else if (quantizationTableSpec >> 4 === 1) { + for(j = 0; j < 64; j++){ + const z = dctZigZag[j]; + tableData[z] = readUint16(); + } + } else { + throw new Error("DQT: invalid table spec"); + } + quantizationTables[quantizationTableSpec & 15] = tableData; + } + break; + case 65472: + case 65473: + case 65474: + readUint16(); + frame = { + }; + frame.extended = fileMarker === 65473; + frame.progressive = fileMarker === 65474; + frame.precision = data[offset++]; + frame.scanLines = readUint16(); + frame.samplesPerLine = readUint16(); + frame.components = { + }; + frame.componentsOrder = []; + let componentsCount = data[offset++], componentId; + for(i = 0; i < componentsCount; i++){ + componentId = data[offset]; + const h = data[offset + 1] >> 4; + const v = data[offset + 1] & 15; + const qId = data[offset + 2]; + frame.componentsOrder.push(componentId); + frame.components[componentId] = { + h: h, + v: v, + quantizationIdx: qId + }; + offset += 3; + } + prepareComponents(frame); + frames.push(frame); + break; + case 65476: + const huffmanLength = readUint16(); + for(i = 2; i < huffmanLength;){ + const huffmanTableSpec = data[offset++]; + const codeLengths = new Uint8Array(16); + let codeLengthSum = 0; + for(j = 0; j < 16; j++, offset++){ + codeLengthSum += codeLengths[j] = data[offset]; + } + const huffmanValues = new Uint8Array(codeLengthSum); + for(j = 0; j < codeLengthSum; j++, offset++){ + huffmanValues[j] = data[offset]; + } + i += 17 + codeLengthSum; + (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues); + } + break; + case 65501: + readUint16(); + resetInterval = readUint16(); + break; + case 65498: + readUint16(); + const selectorsCount = data[offset++]; + let components = [], component; + for(i = 0; i < selectorsCount; i++){ + component = frame.components[data[offset++]]; + const tableSpec = data[offset++]; + component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; + component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; + components.push(component); + } + const spectralStart = data[offset++]; + const spectralEnd = data[offset++]; + const successiveApproximation = data[offset++]; + const processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15); + offset += processed; + break; + case 65535: + if (data[offset] !== 255) { + offset--; + } + break; + default: + if (data[offset - 3] == 255 && data[offset - 2] >= 192 && data[offset - 2] <= 254) { + offset -= 3; + break; + } + throw new Error("unknown JPEG marker " + fileMarker.toString(16)); + } + fileMarker = readUint16(); + } + if (frames.length != 1) { + throw new Error("only single frame JPEGs supported"); + } + for(let i = 0; i < frames.length; i++){ + const cp = frames[i].components; + for(const j in cp){ + cp[j].quantizationTable = quantizationTables[cp[j].quantizationIdx]; + delete cp[j].quantizationIdx; + } + } + this.width = frame.samplesPerLine; + this.height = frame.scanLines; + this.jfif = jfif; + this.adobe = adobe; + this.components = []; + for(let i1 = 0; i1 < frame.componentsOrder.length; i1++){ + const component = frame.components[frame.componentsOrder[i1]]; + this.components.push({ + lines: buildComponentData(frame, component), + scaleX: component.h / frame.maxH, + scaleY: component.v / frame.maxV + }); + } + }, + getData: function getData(width, height) { + const scaleX = this.width / width, scaleY = this.height / height; + let component1, component2, component3, component4; + let component1Line, component2Line, component3Line, component4Line; + let x, y; + let offset = 0; + let Y, Cb, Cr, K, C, M, Ye, R, G, B; + let colorTransform; + const dataLength = width * height * this.components.length; + const data = new Uint8Array(dataLength); + switch(this.components.length){ + case 1: + component1 = this.components[0]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + for(x = 0; x < width; x++){ + Y = component1Line[0 | x * component1.scaleX * scaleX]; + data[offset++] = Y; + } + } + break; + case 2: + component1 = this.components[0]; + component2 = this.components[1]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + component2Line = component2.lines[0 | y * component2.scaleY * scaleY]; + for(x = 0; x < width; x++){ + Y = component1Line[0 | x * component1.scaleX * scaleX]; + data[offset++] = Y; + Y = component2Line[0 | x * component2.scaleX * scaleX]; + data[offset++] = Y; + } + } + break; + case 3: + colorTransform = true; + if (this.adobe && this.adobe.transformCode) { + colorTransform = true; + } else if (typeof this.colorTransform !== "undefined") { + colorTransform = !!this.colorTransform; + } + component1 = this.components[0]; + component2 = this.components[1]; + component3 = this.components[2]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + component2Line = component2.lines[0 | y * component2.scaleY * scaleY]; + component3Line = component3.lines[0 | y * component3.scaleY * scaleY]; + for(x = 0; x < width; x++){ + if (!colorTransform) { + R = component1Line[0 | x * component1.scaleX * scaleX]; + G = component2Line[0 | x * component2.scaleX * scaleX]; + B = component3Line[0 | x * component3.scaleX * scaleX]; + } else { + Y = component1Line[0 | x * component1.scaleX * scaleX]; + Cb = component2Line[0 | x * component2.scaleX * scaleX]; + Cr = component3Line[0 | x * component3.scaleX * scaleX]; + R = clampTo8bit(Y + 1.402 * (Cr - 128)); + G = clampTo8bit(Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128)); + B = clampTo8bit(Y + 1.772 * (Cb - 128)); + } + data[offset++] = R; + data[offset++] = G; + data[offset++] = B; + } + } + break; + case 4: + if (!this.adobe) { + throw new Error("Unsupported color mode (4 components)"); + } + colorTransform = false; + if (this.adobe && this.adobe.transformCode) { + colorTransform = true; + } else if (typeof this.colorTransform !== "undefined") { + colorTransform = !!this.colorTransform; + } + component1 = this.components[0]; + component2 = this.components[1]; + component3 = this.components[2]; + component4 = this.components[3]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + component2Line = component2.lines[0 | y * component2.scaleY * scaleY]; + component3Line = component3.lines[0 | y * component3.scaleY * scaleY]; + component4Line = component4.lines[0 | y * component4.scaleY * scaleY]; + for(x = 0; x < width; x++){ + if (!colorTransform) { + C = component1Line[0 | x * component1.scaleX * scaleX]; + M = component2Line[0 | x * component2.scaleX * scaleX]; + Ye = component3Line[0 | x * component3.scaleX * scaleX]; + K = component4Line[0 | x * component4.scaleX * scaleX]; + } else { + Y = component1Line[0 | x * component1.scaleX * scaleX]; + Cb = component2Line[0 | x * component2.scaleX * scaleX]; + Cr = component3Line[0 | x * component3.scaleX * scaleX]; + K = component4Line[0 | x * component4.scaleX * scaleX]; + C = 255 - clampTo8bit(Y + 1.402 * (Cr - 128)); + M = 255 - clampTo8bit(Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128)); + Ye = 255 - clampTo8bit(Y + 1.772 * (Cb - 128)); + } + data[offset++] = 255 - C; + data[offset++] = 255 - M; + data[offset++] = 255 - Ye; + data[offset++] = 255 - K; + } + } + break; + default: + throw new Error("Unsupported color mode"); + } + return data; + }, + copyToImageData: function copyToImageData(imageData) { + const width = imageData.width, height = imageData.height; + const imageDataArray = imageData.data; + const data = this.getData(width, height); + let i = 0, j = 0, x, y; + let Y, K, C, M, R, G, B; + switch(this.components.length){ + case 1: + for(y = 0; y < height; y++){ + for(x = 0; x < width; x++){ + Y = data[i++]; + imageDataArray[j++] = Y; + imageDataArray[j++] = Y; + imageDataArray[j++] = Y; + imageDataArray[j++] = 255; + } + } + break; + case 3: + for(y = 0; y < height; y++){ + for(x = 0; x < width; x++){ + R = data[i++]; + G = data[i++]; + B = data[i++]; + imageDataArray[j++] = R; + imageDataArray[j++] = G; + imageDataArray[j++] = B; + imageDataArray[j++] = 255; + } + } + break; + case 4: + for(y = 0; y < height; y++){ + for(x = 0; x < width; x++){ + C = data[i++]; + M = data[i++]; + Y = data[i++]; + K = data[i++]; + R = 255 - clampTo8bit(C * (1 - K / 255) + K); + G = 255 - clampTo8bit(M * (1 - K / 255) + K); + B = 255 - clampTo8bit(Y * (1 - K / 255) + K); + imageDataArray[j++] = R; + imageDataArray[j++] = G; + imageDataArray[j++] = B; + imageDataArray[j++] = 255; + } + } + break; + default: + throw new Error("Unsupported color mode"); + } + } + }; + return constructor; +}(); +class Image1 { + getPixel(x, y) { + const index = x + y * this.width; + const rntVal = { + r: this.data[index * 4], + g: this.data[index * 4 + 1], + b: this.data[index * 4 + 2], + a: this.data[index * 4 + 3] + }; + return rntVal; + } + setPixel(x, y, pix) { + const index = x + y * this.width; + this.data[index * 4] = pix.r; + this.data[index * 4 + 1] = pix.g; + this.data[index * 4 + 2] = pix.b; + this.data[index * 4 + 3] = pix.a; + } +} +const decode1 = function(jpegData, colorTransform = true) { + const arr = new Uint8Array(jpegData); + const decoder = new JpegImage(); + decoder.parse(arr); + decoder.colorTransform = colorTransform; + const image = new Image1(); + image.height = decoder.height; + image.width = decoder.width; + image.data = new Uint8Array(decoder.width * decoder.height * 4); + decoder.copyToImageData(image); + return image; +}; +export { decode1 as decode }; diff --git a/bundler/tests/fixture/deno-9220/case1/output/entry.ts b/bundler/tests/fixture/deno-9220/case1/output/entry.ts new file mode 100644 index 000000000000..4d97b5b07932 --- /dev/null +++ b/bundler/tests/fixture/deno-9220/case1/output/entry.ts @@ -0,0 +1,962 @@ +const JpegImage = function jpegImage() { + "use strict"; + const dctZigZag = new Int32Array([ + 0, + 1, + 8, + 16, + 9, + 2, + 3, + 10, + 17, + 24, + 32, + 25, + 18, + 11, + 4, + 5, + 12, + 19, + 26, + 33, + 40, + 48, + 41, + 34, + 27, + 20, + 13, + 6, + 7, + 14, + 21, + 28, + 35, + 42, + 49, + 56, + 57, + 50, + 43, + 36, + 29, + 22, + 15, + 23, + 30, + 37, + 44, + 51, + 58, + 59, + 52, + 45, + 38, + 31, + 39, + 46, + 53, + 60, + 61, + 54, + 47, + 55, + 62, + 63 + ]); + const dctCos1 = 4017; + const dctSin1 = 799; + const dctCos3 = 3406; + const dctSin3 = 2276; + const dctCos6 = 1567; + const dctSin6 = 3784; + const dctSqrt2 = 5793; + const dctSqrt1d2 = 2896; + function constructor() { + } + function buildHuffmanTable(codeLengths, values) { + let k = 0; + const code = []; + let i, j, length = 16; + while(length > 0 && !codeLengths[length - 1]){ + length--; + } + code.push({ + children: [], + index: 0 + }); + let p = code[0], q; + for(i = 0; i < length; i++){ + for(j = 0; j < codeLengths[i]; j++){ + p = code.pop(); + p.children[p.index] = values[k]; + while(p.index > 0){ + p = code.pop(); + } + p.index++; + code.push(p); + while(code.length <= i){ + code.push(q = { + children: [], + index: 0 + }); + p.children[p.index] = q.children; + p = q; + } + k++; + } + if (i + 1 < length) { + code.push(q = { + children: [], + index: 0 + }); + p.children[p.index] = q.children; + p = q; + } + } + return code[0].children; + } + function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) { + const mcusPerLine = frame.mcusPerLine; + const progressive = frame.progressive; + const startOffset = offset; + let bitsData = 0, bitsCount = 0; + function readBit() { + if (bitsCount > 0) { + bitsCount--; + return bitsData >> bitsCount & 1; + } + bitsData = data[offset++]; + if (bitsData === 255) { + const nextByte = data[offset++]; + if (nextByte) { + throw new Error("unexpected marker: " + (bitsData << 8 | nextByte).toString(16)); + } + } + bitsCount = 7; + return bitsData >>> 7; + } + function decodeHuffman(tree) { + let node = tree, bit; + while((bit = readBit()) !== null){ + node = node[bit]; + if (typeof node === "number") { + return node; + } + if (typeof node !== "object") { + throw new Error("invalid huffman sequence"); + } + } + return null; + } + function receive(length) { + let n = 0; + while(length > 0){ + const bit = readBit(); + if (bit === null) { + return; + } + n = n << 1 | bit; + length--; + } + return n; + } + function receiveAndExtend(length) { + const n = receive(length); + if (n >= 1 << length - 1) { + return n; + } + return n + (-1 << length) + 1; + } + function decodeBaseline(component, zz) { + const t = decodeHuffman(component.huffmanTableDC); + const diff = t === 0 ? 0 : receiveAndExtend(t); + zz[0] = component.pred += diff; + let k = 1; + while(k < 64){ + const rs = decodeHuffman(component.huffmanTableAC); + const s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + break; + } + k += 16; + continue; + } + k += r; + const z = dctZigZag[k]; + zz[z] = receiveAndExtend(s); + k++; + } + } + function decodeDCFirst(component, zz) { + const t = decodeHuffman(component.huffmanTableDC); + const diff = t === 0 ? 0 : receiveAndExtend(t) << successive; + zz[0] = component.pred += diff; + } + function decodeDCSuccessive(component, zz) { + zz[0] |= readBit() << successive; + } + let eobrun = 0; + function decodeACFirst(component, zz) { + if (eobrun > 0) { + eobrun--; + return; + } + let k = spectralStart, e = spectralEnd; + while(k <= e){ + const rs = decodeHuffman(component.huffmanTableAC); + const s = rs & 15, r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r) - 1; + break; + } + k += 16; + continue; + } + k += r; + const z = dctZigZag[k]; + zz[z] = receiveAndExtend(s) * (1 << successive); + k++; + } + } + let successiveACState = 0, successiveACNextValue; + function decodeACSuccessive(component, zz) { + let k = spectralStart, e = spectralEnd, r = 0; + while(k <= e){ + const z = dctZigZag[k]; + const direction = zz[z] < 0 ? -1 : 1; + switch(successiveACState){ + case 0: + const rs = decodeHuffman(component.huffmanTableAC); + const s = rs & 15; + r = rs >> 4; + if (s === 0) { + if (r < 15) { + eobrun = receive(r) + (1 << r); + successiveACState = 4; + } else { + r = 16; + successiveACState = 1; + } + } else { + if (s !== 1) { + throw new Error("invalid ACn encoding"); + } + successiveACNextValue = receiveAndExtend(s); + successiveACState = r ? 2 : 3; + } + continue; + case 1: + case 2: + if (zz[z]) { + zz[z] += (readBit() << successive) * direction; + } else { + r--; + if (r === 0) { + successiveACState = successiveACState == 2 ? 3 : 0; + } + } + break; + case 3: + if (zz[z]) { + zz[z] += (readBit() << successive) * direction; + } else { + zz[z] = successiveACNextValue << successive; + successiveACState = 0; + } + break; + case 4: + if (zz[z]) { + zz[z] += (readBit() << successive) * direction; + } + break; + } + k++; + } + if (successiveACState === 4) { + eobrun--; + if (eobrun === 0) { + successiveACState = 0; + } + } + } + function decodeMcu(component, decode, mcu, row, col) { + const mcuRow = mcu / mcusPerLine | 0; + const mcuCol = mcu % mcusPerLine; + const blockRow = mcuRow * component.v + row; + const blockCol = mcuCol * component.h + col; + decode(component, component.blocks[blockRow][blockCol]); + } + function decodeBlock(component, decode, mcu) { + const blockRow = mcu / component.blocksPerLine | 0; + const blockCol = mcu % component.blocksPerLine; + decode(component, component.blocks[blockRow][blockCol]); + } + const componentsLength = components.length; + let component, i, j, k, n; + let decodeFn; + if (progressive) { + if (spectralStart === 0) { + decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; + } else { + decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; + } + } else { + decodeFn = decodeBaseline; + } + let mcu = 0, marker; + let mcuExpected; + if (componentsLength == 1) { + mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; + } else { + mcuExpected = mcusPerLine * frame.mcusPerColumn; + } + if (!resetInterval) { + resetInterval = mcuExpected; + } + let h, v; + while(mcu < mcuExpected){ + for(i = 0; i < componentsLength; i++){ + components[i].pred = 0; + } + eobrun = 0; + if (componentsLength == 1) { + component = components[0]; + for(n = 0; n < resetInterval; n++){ + decodeBlock(component, decodeFn, mcu); + mcu++; + } + } else { + for(n = 0; n < resetInterval; n++){ + for(i = 0; i < componentsLength; i++){ + component = components[i]; + h = component.h; + v = component.v; + for(j = 0; j < v; j++){ + for(k = 0; k < h; k++){ + decodeMcu(component, decodeFn, mcu, j, k); + } + } + } + mcu++; + if (mcu === mcuExpected) { + break; + } + } + } + bitsCount = 0; + marker = data[offset] << 8 | data[offset + 1]; + if (marker < 65280) { + throw new Error("marker was not found"); + } + if (marker >= 65488 && marker <= 65495) { + offset += 2; + } else { + break; + } + } + return offset - startOffset; + } + function buildComponentData(frame, component) { + const lines = []; + const blocksPerLine = component.blocksPerLine; + const blocksPerColumn = component.blocksPerColumn; + const samplesPerLine = blocksPerLine << 3; + const R = new Int32Array(64), r = new Uint8Array(64); + function quantizeAndInverse(zz, dataOut, dataIn) { + const qt = component.quantizationTable; + let v0, v1, v2, v3, v4, v5, v6, v7, t; + const p = dataIn; + let i; + for(i = 0; i < 64; i++){ + p[i] = zz[i] * qt[i]; + } + for(i = 0; i < 8; ++i){ + const row = 8 * i; + if (p[1 + row] == 0 && p[2 + row] == 0 && p[3 + row] == 0 && p[4 + row] == 0 && p[5 + row] == 0 && p[6 + row] == 0 && p[7 + row] == 0) { + t = dctSqrt2 * p[0 + row] + 512 >> 10; + p[0 + row] = t; + p[1 + row] = t; + p[2 + row] = t; + p[3 + row] = t; + p[4 + row] = t; + p[5 + row] = t; + p[6 + row] = t; + p[7 + row] = t; + continue; + } + v0 = dctSqrt2 * p[0 + row] + 128 >> 8; + v1 = dctSqrt2 * p[4 + row] + 128 >> 8; + v2 = p[2 + row]; + v3 = p[6 + row]; + v4 = dctSqrt1d2 * (p[1 + row] - p[7 + row]) + 128 >> 8; + v7 = dctSqrt1d2 * (p[1 + row] + p[7 + row]) + 128 >> 8; + v5 = p[3 + row] << 4; + v6 = p[5 + row] << 4; + t = v0 - v1 + 1 >> 1; + v0 = v0 + v1 + 1 >> 1; + v1 = t; + t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8; + v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8; + v3 = t; + t = v4 - v6 + 1 >> 1; + v4 = v4 + v6 + 1 >> 1; + v6 = t; + t = v7 + v5 + 1 >> 1; + v5 = v7 - v5 + 1 >> 1; + v7 = t; + t = v0 - v3 + 1 >> 1; + v0 = v0 + v3 + 1 >> 1; + v3 = t; + t = v1 - v2 + 1 >> 1; + v1 = v1 + v2 + 1 >> 1; + v2 = t; + t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; + v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; + v7 = t; + t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; + v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; + v6 = t; + p[0 + row] = v0 + v7; + p[7 + row] = v0 - v7; + p[1 + row] = v1 + v6; + p[6 + row] = v1 - v6; + p[2 + row] = v2 + v5; + p[5 + row] = v2 - v5; + p[3 + row] = v3 + v4; + p[4 + row] = v3 - v4; + } + for(i = 0; i < 8; ++i){ + const col = i; + if (p[1 * 8 + col] == 0 && p[2 * 8 + col] == 0 && p[3 * 8 + col] == 0 && p[4 * 8 + col] == 0 && p[5 * 8 + col] == 0 && p[6 * 8 + col] == 0 && p[7 * 8 + col] == 0) { + t = dctSqrt2 * dataIn[i + 0] + 8192 >> 14; + p[0 * 8 + col] = t; + p[1 * 8 + col] = t; + p[2 * 8 + col] = t; + p[3 * 8 + col] = t; + p[4 * 8 + col] = t; + p[5 * 8 + col] = t; + p[6 * 8 + col] = t; + p[7 * 8 + col] = t; + continue; + } + v0 = dctSqrt2 * p[0 * 8 + col] + 2048 >> 12; + v1 = dctSqrt2 * p[4 * 8 + col] + 2048 >> 12; + v2 = p[2 * 8 + col]; + v3 = p[6 * 8 + col]; + v4 = dctSqrt1d2 * (p[1 * 8 + col] - p[7 * 8 + col]) + 2048 >> 12; + v7 = dctSqrt1d2 * (p[1 * 8 + col] + p[7 * 8 + col]) + 2048 >> 12; + v5 = p[3 * 8 + col]; + v6 = p[5 * 8 + col]; + t = v0 - v1 + 1 >> 1; + v0 = v0 + v1 + 1 >> 1; + v1 = t; + t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12; + v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12; + v3 = t; + t = v4 - v6 + 1 >> 1; + v4 = v4 + v6 + 1 >> 1; + v6 = t; + t = v7 + v5 + 1 >> 1; + v5 = v7 - v5 + 1 >> 1; + v7 = t; + t = v0 - v3 + 1 >> 1; + v0 = v0 + v3 + 1 >> 1; + v3 = t; + t = v1 - v2 + 1 >> 1; + v1 = v1 + v2 + 1 >> 1; + v2 = t; + t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12; + v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12; + v7 = t; + t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12; + v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12; + v6 = t; + p[0 * 8 + col] = v0 + v7; + p[7 * 8 + col] = v0 - v7; + p[1 * 8 + col] = v1 + v6; + p[6 * 8 + col] = v1 - v6; + p[2 * 8 + col] = v2 + v5; + p[5 * 8 + col] = v2 - v5; + p[3 * 8 + col] = v3 + v4; + p[4 * 8 + col] = v3 - v4; + } + for(i = 0; i < 64; ++i){ + const sample = 128 + (p[i] + 8 >> 4); + dataOut[i] = sample < 0 ? 0 : sample > 255 ? 255 : sample; + } + } + let i, j; + for(let blockRow = 0; blockRow < blocksPerColumn; blockRow++){ + const scanLine = blockRow << 3; + for(i = 0; i < 8; i++){ + lines.push(new Uint8Array(samplesPerLine)); + } + for(let blockCol = 0; blockCol < blocksPerLine; blockCol++){ + quantizeAndInverse(component.blocks[blockRow][blockCol], r, R); + let offset = 0, sample = blockCol << 3; + for(j = 0; j < 8; j++){ + const line = lines[scanLine + j]; + for(i = 0; i < 8; i++){ + line[sample + i] = r[offset++]; + } + } + } + } + return lines; + } + function clampTo8bit(a) { + return a < 0 ? 0 : a > 255 ? 255 : a; + } + constructor.prototype = { + load: function load(path) { + }, + parse: function parse(data) { + let offset = 0; + function readUint16() { + const value = data[offset] << 8 | data[offset + 1]; + offset += 2; + return value; + } + function readDataBlock() { + const length = readUint16(); + const array = data.subarray(offset, offset + length - 2); + offset += array.length; + return array; + } + function prepareComponents(frame) { + let maxH = 0, maxV = 0; + let component, componentId; + for(componentId in frame.components){ + if (frame.components.hasOwnProperty(componentId)) { + component = frame.components[componentId]; + if (maxH < component.h) { + maxH = component.h; + } + if (maxV < component.v) { + maxV = component.v; + } + } + } + const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / maxH); + const mcusPerColumn = Math.ceil(frame.scanLines / 8 / maxV); + for(componentId in frame.components){ + if (frame.components.hasOwnProperty(componentId)) { + component = frame.components[componentId]; + const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / maxH); + const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / maxV); + const blocksPerLineForMcu = mcusPerLine * component.h; + const blocksPerColumnForMcu = mcusPerColumn * component.v; + const blocks = []; + for(let i = 0; i < blocksPerColumnForMcu; i++){ + const row = []; + for(let j = 0; j < blocksPerLineForMcu; j++){ + row.push(new Int32Array(64)); + } + blocks.push(row); + } + component.blocksPerLine = blocksPerLine; + component.blocksPerColumn = blocksPerColumn; + component.blocks = blocks; + } + } + frame.maxH = maxH; + frame.maxV = maxV; + frame.mcusPerLine = mcusPerLine; + frame.mcusPerColumn = mcusPerColumn; + } + let jfif = null; + let adobe = null; + let frame, resetInterval; + const quantizationTables = [], frames = []; + const huffmanTablesAC = [], huffmanTablesDC = []; + let fileMarker = readUint16(); + if (fileMarker != 65496) { + throw new Error("SOI not found"); + } + fileMarker = readUint16(); + while(fileMarker != 65497){ + let i, j, l; + switch(fileMarker){ + case 65280: break; + case 65504: + case 65505: + case 65506: + case 65507: + case 65508: + case 65509: + case 65510: + case 65511: + case 65512: + case 65513: + case 65514: + case 65515: + case 65516: + case 65517: + case 65518: + case 65519: + case 65534: + const appData = readDataBlock(); + if (fileMarker === 65504) { + if (appData[0] === 74 && appData[1] === 70 && appData[2] === 73 && appData[3] === 70 && appData[4] === 0) { + jfif = { + version: { + major: appData[5], + minor: appData[6] + }, + densityUnits: appData[7], + xDensity: appData[8] << 8 | appData[9], + yDensity: appData[10] << 8 | appData[11], + thumbWidth: appData[12], + thumbHeight: appData[13], + thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13]) + }; + } + } + if (fileMarker === 65518) { + if (appData[0] === 65 && appData[1] === 100 && appData[2] === 111 && appData[3] === 98 && appData[4] === 101 && appData[5] === 0) { + adobe = { + version: appData[6], + flags0: appData[7] << 8 | appData[8], + flags1: appData[9] << 8 | appData[10], + transformCode: appData[11] + }; + } + } + break; + case 65499: + const quantizationTablesLength = readUint16(); + const quantizationTablesEnd = quantizationTablesLength + offset - 2; + while(offset < quantizationTablesEnd){ + const quantizationTableSpec = data[offset++]; + const tableData = new Int32Array(64); + if (quantizationTableSpec >> 4 === 0) { + for(j = 0; j < 64; j++){ + const z = dctZigZag[j]; + tableData[z] = data[offset++]; + } + } else if (quantizationTableSpec >> 4 === 1) { + for(j = 0; j < 64; j++){ + const z = dctZigZag[j]; + tableData[z] = readUint16(); + } + } else { + throw new Error("DQT: invalid table spec"); + } + quantizationTables[quantizationTableSpec & 15] = tableData; + } + break; + case 65472: + case 65473: + case 65474: + readUint16(); + frame = { + }; + frame.extended = fileMarker === 65473; + frame.progressive = fileMarker === 65474; + frame.precision = data[offset++]; + frame.scanLines = readUint16(); + frame.samplesPerLine = readUint16(); + frame.components = { + }; + frame.componentsOrder = []; + let componentsCount = data[offset++], componentId; + for(i = 0; i < componentsCount; i++){ + componentId = data[offset]; + const h = data[offset + 1] >> 4; + const v = data[offset + 1] & 15; + const qId = data[offset + 2]; + frame.componentsOrder.push(componentId); + frame.components[componentId] = { + h: h, + v: v, + quantizationIdx: qId + }; + offset += 3; + } + prepareComponents(frame); + frames.push(frame); + break; + case 65476: + const huffmanLength = readUint16(); + for(i = 2; i < huffmanLength;){ + const huffmanTableSpec = data[offset++]; + const codeLengths = new Uint8Array(16); + let codeLengthSum = 0; + for(j = 0; j < 16; j++, offset++){ + codeLengthSum += codeLengths[j] = data[offset]; + } + const huffmanValues = new Uint8Array(codeLengthSum); + for(j = 0; j < codeLengthSum; j++, offset++){ + huffmanValues[j] = data[offset]; + } + i += 17 + codeLengthSum; + (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues); + } + break; + case 65501: + readUint16(); + resetInterval = readUint16(); + break; + case 65498: + readUint16(); + const selectorsCount = data[offset++]; + let components = [], component; + for(i = 0; i < selectorsCount; i++){ + component = frame.components[data[offset++]]; + const tableSpec = data[offset++]; + component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; + component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; + components.push(component); + } + const spectralStart = data[offset++]; + const spectralEnd = data[offset++]; + const successiveApproximation = data[offset++]; + const processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15); + offset += processed; + break; + case 65535: + if (data[offset] !== 255) { + offset--; + } + break; + default: + if (data[offset - 3] == 255 && data[offset - 2] >= 192 && data[offset - 2] <= 254) { + offset -= 3; + break; + } + throw new Error("unknown JPEG marker " + fileMarker.toString(16)); + } + fileMarker = readUint16(); + } + if (frames.length != 1) { + throw new Error("only single frame JPEGs supported"); + } + for(let i = 0; i < frames.length; i++){ + const cp = frames[i].components; + for(const j in cp){ + cp[j].quantizationTable = quantizationTables[cp[j].quantizationIdx]; + delete cp[j].quantizationIdx; + } + } + this.width = frame.samplesPerLine; + this.height = frame.scanLines; + this.jfif = jfif; + this.adobe = adobe; + this.components = []; + for(let i1 = 0; i1 < frame.componentsOrder.length; i1++){ + const component = frame.components[frame.componentsOrder[i1]]; + this.components.push({ + lines: buildComponentData(frame, component), + scaleX: component.h / frame.maxH, + scaleY: component.v / frame.maxV + }); + } + }, + getData: function getData(width, height) { + const scaleX = this.width / width, scaleY = this.height / height; + let component1, component2, component3, component4; + let component1Line, component2Line, component3Line, component4Line; + let x, y; + let offset = 0; + let Y, Cb, Cr, K, C, M, Ye, R, G, B; + let colorTransform; + const dataLength = width * height * this.components.length; + const data = new Uint8Array(dataLength); + switch(this.components.length){ + case 1: + component1 = this.components[0]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + for(x = 0; x < width; x++){ + Y = component1Line[0 | x * component1.scaleX * scaleX]; + data[offset++] = Y; + } + } + break; + case 2: + component1 = this.components[0]; + component2 = this.components[1]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + component2Line = component2.lines[0 | y * component2.scaleY * scaleY]; + for(x = 0; x < width; x++){ + Y = component1Line[0 | x * component1.scaleX * scaleX]; + data[offset++] = Y; + Y = component2Line[0 | x * component2.scaleX * scaleX]; + data[offset++] = Y; + } + } + break; + case 3: + colorTransform = true; + if (this.adobe && this.adobe.transformCode) { + colorTransform = true; + } else if (typeof this.colorTransform !== "undefined") { + colorTransform = !!this.colorTransform; + } + component1 = this.components[0]; + component2 = this.components[1]; + component3 = this.components[2]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + component2Line = component2.lines[0 | y * component2.scaleY * scaleY]; + component3Line = component3.lines[0 | y * component3.scaleY * scaleY]; + for(x = 0; x < width; x++){ + if (!colorTransform) { + R = component1Line[0 | x * component1.scaleX * scaleX]; + G = component2Line[0 | x * component2.scaleX * scaleX]; + B = component3Line[0 | x * component3.scaleX * scaleX]; + } else { + Y = component1Line[0 | x * component1.scaleX * scaleX]; + Cb = component2Line[0 | x * component2.scaleX * scaleX]; + Cr = component3Line[0 | x * component3.scaleX * scaleX]; + R = clampTo8bit(Y + 1.402 * (Cr - 128)); + G = clampTo8bit(Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128)); + B = clampTo8bit(Y + 1.772 * (Cb - 128)); + } + data[offset++] = R; + data[offset++] = G; + data[offset++] = B; + } + } + break; + case 4: + if (!this.adobe) { + throw new Error("Unsupported color mode (4 components)"); + } + colorTransform = false; + if (this.adobe && this.adobe.transformCode) { + colorTransform = true; + } else if (typeof this.colorTransform !== "undefined") { + colorTransform = !!this.colorTransform; + } + component1 = this.components[0]; + component2 = this.components[1]; + component3 = this.components[2]; + component4 = this.components[3]; + for(y = 0; y < height; y++){ + component1Line = component1.lines[0 | y * component1.scaleY * scaleY]; + component2Line = component2.lines[0 | y * component2.scaleY * scaleY]; + component3Line = component3.lines[0 | y * component3.scaleY * scaleY]; + component4Line = component4.lines[0 | y * component4.scaleY * scaleY]; + for(x = 0; x < width; x++){ + if (!colorTransform) { + C = component1Line[0 | x * component1.scaleX * scaleX]; + M = component2Line[0 | x * component2.scaleX * scaleX]; + Ye = component3Line[0 | x * component3.scaleX * scaleX]; + K = component4Line[0 | x * component4.scaleX * scaleX]; + } else { + Y = component1Line[0 | x * component1.scaleX * scaleX]; + Cb = component2Line[0 | x * component2.scaleX * scaleX]; + Cr = component3Line[0 | x * component3.scaleX * scaleX]; + K = component4Line[0 | x * component4.scaleX * scaleX]; + C = 255 - clampTo8bit(Y + 1.402 * (Cr - 128)); + M = 255 - clampTo8bit(Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128)); + Ye = 255 - clampTo8bit(Y + 1.772 * (Cb - 128)); + } + data[offset++] = 255 - C; + data[offset++] = 255 - M; + data[offset++] = 255 - Ye; + data[offset++] = 255 - K; + } + } + break; + default: + throw new Error("Unsupported color mode"); + } + return data; + }, + copyToImageData: function copyToImageData(imageData) { + const width = imageData.width, height = imageData.height; + const imageDataArray = imageData.data; + const data = this.getData(width, height); + let i = 0, j = 0, x, y; + let Y, K, C, M, R, G, B; + switch(this.components.length){ + case 1: + for(y = 0; y < height; y++){ + for(x = 0; x < width; x++){ + Y = data[i++]; + imageDataArray[j++] = Y; + imageDataArray[j++] = Y; + imageDataArray[j++] = Y; + imageDataArray[j++] = 255; + } + } + break; + case 3: + for(y = 0; y < height; y++){ + for(x = 0; x < width; x++){ + R = data[i++]; + G = data[i++]; + B = data[i++]; + imageDataArray[j++] = R; + imageDataArray[j++] = G; + imageDataArray[j++] = B; + imageDataArray[j++] = 255; + } + } + break; + case 4: + for(y = 0; y < height; y++){ + for(x = 0; x < width; x++){ + C = data[i++]; + M = data[i++]; + Y = data[i++]; + K = data[i++]; + R = 255 - clampTo8bit(C * (1 - K / 255) + K); + G = 255 - clampTo8bit(M * (1 - K / 255) + K); + B = 255 - clampTo8bit(Y * (1 - K / 255) + K); + imageDataArray[j++] = R; + imageDataArray[j++] = G; + imageDataArray[j++] = B; + imageDataArray[j++] = 255; + } + } + break; + default: + throw new Error("Unsupported color mode"); + } + } + }; + return constructor; +}(); +class Image1 { + getPixel(x, y) { + const index = x + y * this.width; + const rntVal = { + r: this.data[index * 4], + g: this.data[index * 4 + 1], + b: this.data[index * 4 + 2], + a: this.data[index * 4 + 3] + }; + return rntVal; + } + setPixel(x, y, pix) { + const index = x + y * this.width; + this.data[index * 4] = pix.r; + this.data[index * 4 + 1] = pix.g; + this.data[index * 4 + 2] = pix.b; + this.data[index * 4 + 3] = pix.a; + } +} +const Image2 = Image1; +const Image3 = Image2; +const decode1 = function(jpegData, colorTransform = true) { + const arr = new Uint8Array(jpegData); + const decoder = new JpegImage(); + decoder.parse(arr); + decoder.colorTransform = colorTransform; + const image = new Image3(); + image.height = decoder.height; + image.width = decoder.width; + image.data = new Uint8Array(decoder.width * decoder.height * 4); + decoder.copyToImageData(image); + return image; +}; +export { decode1 as decode }; diff --git a/bundler/tests/fixture/issue-1150-2/output/entry.inlined.ts b/bundler/tests/fixture/issue-1150-2/output/entry.inlined.ts index 9b5d66be6a98..78f54a7ea683 100644 --- a/bundler/tests/fixture/issue-1150-2/output/entry.inlined.ts +++ b/bundler/tests/fixture/issue-1150-2/output/entry.inlined.ts @@ -1,21 +1,25 @@ -var O1; +var O3; (function(O1) { O1[O1["A"] = 0] = "A"; O1[O1["B"] = 1] = "B"; O1[O1["C"] = 2] = "C"; -})(O1 || (O1 = { +})(O3 || (O3 = { })); function a() { console.log("a"); } -export { O1 as O }; +const a1 = a; +const a2 = a1; +const O1 = O3; +const O2 = O1; +export { O2 as O }; class A { #a; #c; constructor(o = { }){ - const { a: a1 = a , c , } = o; - this.#a = a1; + const { a: a3 = a2 , c , } = o; + this.#a = a3; this.#c = c; } a() { @@ -25,6 +29,6 @@ class A { console.log(this.#c); } } -let a2 = new A(); -a2.a(); -a2.c(); +let a4 = new A(); +a4.a(); +a4.c(); diff --git a/bundler/tests/fixture/issue-1150/output/entry.inlined.ts b/bundler/tests/fixture/issue-1150/output/entry.inlined.ts index 9b5d66be6a98..78f54a7ea683 100644 --- a/bundler/tests/fixture/issue-1150/output/entry.inlined.ts +++ b/bundler/tests/fixture/issue-1150/output/entry.inlined.ts @@ -1,21 +1,25 @@ -var O1; +var O3; (function(O1) { O1[O1["A"] = 0] = "A"; O1[O1["B"] = 1] = "B"; O1[O1["C"] = 2] = "C"; -})(O1 || (O1 = { +})(O3 || (O3 = { })); function a() { console.log("a"); } -export { O1 as O }; +const a1 = a; +const a2 = a1; +const O1 = O3; +const O2 = O1; +export { O2 as O }; class A { #a; #c; constructor(o = { }){ - const { a: a1 = a , c , } = o; - this.#a = a1; + const { a: a3 = a2 , c , } = o; + this.#a = a3; this.#c = c; } a() { @@ -25,6 +29,6 @@ class A { console.log(this.#c); } } -let a2 = new A(); -a2.a(); -a2.c(); +let a4 = new A(); +a4.a(); +a4.c(); diff --git a/bundler/tests/fixture/sort/enum-reexport/output/entry.inlined.ts b/bundler/tests/fixture/sort/enum-reexport/output/entry.inlined.ts index 5fae6ea65a2f..0ec258080ae6 100644 --- a/bundler/tests/fixture/sort/enum-reexport/output/entry.inlined.ts +++ b/bundler/tests/fixture/sort/enum-reexport/output/entry.inlined.ts @@ -1,6 +1,7 @@ -var Status1; +var Status2; (function(Status1) { Status1[Status1["Continue"] = 100] = "Continue"; -})(Status1 || (Status1 = { +})(Status2 || (Status2 = { })); +const Status1 = Status2; export { Status1 as Status }; diff --git a/bundler/tests/fixture/wrapped/export-named/output/entry.inlined.ts b/bundler/tests/fixture/wrapped/export-named/output/entry.inlined.ts index 3c67b68a2135..407a8c8e6162 100644 --- a/bundler/tests/fixture/wrapped/export-named/output/entry.inlined.ts +++ b/bundler/tests/fixture/wrapped/export-named/output/entry.inlined.ts @@ -3,10 +3,11 @@ const [a, b, c] = [ 2, 3 ]; +const b1 = b; const mod = function() { - const b1 = b; + const b2 = b1; return { - b: b + b: b1 }; }(); console.log(mod); diff --git a/ecmascript/transforms/optimization/src/simplify/const_propgation.rs b/ecmascript/transforms/optimization/src/simplify/const_propgation.rs index 04e97b7ae12c..26980ce59bbd 100644 --- a/ecmascript/transforms/optimization/src/simplify/const_propgation.rs +++ b/ecmascript/transforms/optimization/src/simplify/const_propgation.rs @@ -66,7 +66,11 @@ impl VisitMut for ConstPropagation<'_> { self.scope.vars.insert(name.to_id(), init.clone()); } - Expr::Ident(init) => { + Expr::Ident(init) + if name.span.is_dummy() + || var.span.is_dummy() + || init.span.is_dummy() => + { // This check is required to prevent breaking some codes. if let Some(value) = self.scope.vars.get(&init.to_id()).cloned() { self.scope.vars.insert(name.to_id(), value); @@ -110,7 +114,6 @@ impl VisitMut for ConstPropagation<'_> { match e { Expr::Ident(i) => { if let Some(expr) = self.scope.find_var(&i.to_id()) { - dbg!(&i, &expr); *e = *expr.clone(); return; } diff --git a/scripts/github/get-all-crates.sh b/scripts/github/get-all-crates.sh new file mode 100755 index 000000000000..48e3b27dcf94 --- /dev/null +++ b/scripts/github/get-all-crates.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -eu + +function prepend() { while read line; do echo "${1}${line}"; done; } + +cargo metadata --format-version 1 \ + | jq -r '.workspace_members[]' \ + | cut -f1 -d" " \ + | sort \ + | prepend '- ' diff --git a/tests/fixture/issue-1345/input/.swcrc b/tests/fixture/issue-1345/input/.swcrc new file mode 100644 index 000000000000..95da73bf0082 --- /dev/null +++ b/tests/fixture/issue-1345/input/.swcrc @@ -0,0 +1,21 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": true, + "dynamicImport": true + }, + "transform": { + "legacyDecorator": true, + "decoratorMetadata": true, + "optimizer": { + "globals": { + "vars": { + "__DEBUG__": "true" + } + } + } + } + } +} diff --git a/tests/fixture/issue-1345/input/index.ts b/tests/fixture/issue-1345/input/index.ts new file mode 100644 index 000000000000..61240578ca92 --- /dev/null +++ b/tests/fixture/issue-1345/input/index.ts @@ -0,0 +1,53 @@ +/** 등록된 계좌+회원의 정보 */ +@ViewEntity({ + name: "AccountMemberView", + expression: + ` + SELECT + m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday, + (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="F") as accountCnt, + (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="T") as accountQuickCnt + FROM TBLMEMBER m + `, + // expression: ` + // SELECT + // m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday, + // IFNULL(SUM(IF (use_quick= "F", 1, 0)), 0) as accountCnt, + // IFNULL(SUM(IF (use_quick= "T", 1, 0)), 0) as accountQuickCnt + // FROM TBLMEMBER m + // OUTER JOIN TBLACCOUNT a ON m.mid = a.mid + // `, +}) +export class AccountMemberView { + /** 회원의 순번 */ + @ViewColumn({ name: "tmcode" }) + memberId: number; + + /** 회원의 mall 아이디 */ + @ViewColumn({ name: "mid" }) + mallId: string; + + /** 이용가능한 (일반)계좌수 */ + @ViewColumn({ name: "accea" }) + allowAccountCnt: number; + + /** 이용가능한 퀵 계좌수 */ + @ViewColumn({ name: "qaccea" }) + allowQuickAccountCnt: number; + + /** 이용가능한 (일반)계좌의 기간 */ + @ViewColumn({ name: "endday" }) + accountEnddedAt: Date; + + /** 이용가능한 퀵 계좌의 기간 */ + @ViewColumn({ name: "quick_endday" }) + accountQuickEnddedAt: Date; + + /** 현재등록한 (일반)계좌의 수 (타입: 문자열의 숫자로 출력됨) */ + @ViewColumn() + accountCnt: number; + + /** 현재등록한 퀵 계좌의 수 (타입: 문자열의 숫자로 출력됨) */ + @ViewColumn() + accountQuickCnt: number; +} diff --git a/tests/fixture/issue-1345/output/index.ts b/tests/fixture/issue-1345/output/index.ts new file mode 100644 index 000000000000..b983956a7bb7 --- /dev/null +++ b/tests/fixture/issue-1345/output/index.ts @@ -0,0 +1,134 @@ +function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { + var desc = { + }; + Object.keys(descriptor).forEach(function(key) { + desc[key] = descriptor[key]; + }); + desc.enumerable = !!desc.enumerable; + desc.configurable = !!desc.configurable; + if ("value" in desc || desc.initializer) { + desc.writable = true; + } + desc = decorators.slice().reverse().reduce(function(desc, decorator) { + return decorator(target, property, desc) || desc; + }, desc); + if (context && desc.initializer !== void 0) { + desc.value = desc.initializer ? desc.initializer.call(context) : void 0; + desc.initializer = undefined; + } + if (desc.initializer === void 0) { + Object.defineProperty(target, property, desc); + desc = null; + } + return desc; +} +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} +function _initializerDefineProperty(target, property, descriptor, context) { + if (!descriptor) return; + Object.defineProperty(target, property, { + enumerable: descriptor.enumerable, + configurable: descriptor.configurable, + writable: descriptor.writable, + value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 + }); +} +var _class, _descriptor, _descriptor1, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7; +var _dec = ViewColumn({ + name: "tmcode" +}), _dec1 = ViewColumn({ + name: "mid" +}), _dec2 = ViewColumn({ + name: "accea" +}), _dec3 = ViewColumn({ + name: "qaccea" +}), _dec4 = ViewColumn({ + name: "endday" +}), _dec5 = ViewColumn({ + name: "quick_endday" +}), _dec6 = ViewColumn(), _dec7 = ViewColumn(), _dec8 = ViewEntity({ + name: "AccountMemberView", + expression: "\n SELECT\n m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick=\"F\") as accountCnt,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick=\"T\") as accountQuickCnt\n FROM TBLMEMBER m\n " +}); +export var AccountMemberView = _class = _dec8((_class = function() { + var AccountMemberView1 = function AccountMemberView1() { + "use strict"; + _classCallCheck(this, AccountMemberView1); + _initializerDefineProperty(this, "memberId", _descriptor, this); + _initializerDefineProperty(this, "mallId", _descriptor1, this); + _initializerDefineProperty(this, "allowAccountCnt", _descriptor2, this); + _initializerDefineProperty(this, "allowQuickAccountCnt", _descriptor3, this); + _initializerDefineProperty(this, "accountEnddedAt", _descriptor4, this); + _initializerDefineProperty(this, "accountQuickEnddedAt", _descriptor5, this); + _initializerDefineProperty(this, "accountCnt", _descriptor6, this); + _initializerDefineProperty(this, "accountQuickCnt", _descriptor7, this); + }; + return AccountMemberView1; +}(), _descriptor = _applyDecoratedDescriptor(_class.prototype, "memberId", [ + _dec, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor1 = _applyDecoratedDescriptor(_class.prototype, "mallId", [ + _dec1, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", String) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "allowAccountCnt", [ + _dec2, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "allowQuickAccountCnt", [ + _dec3, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "accountEnddedAt", [ + _dec4, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "accountQuickEnddedAt", [ + _dec5, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "accountCnt", [ + _dec6, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "accountQuickCnt", [ + _dec7, + typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Number) +], { + configurable: true, + enumerable: true, + writable: true, + initializer: void 0 +}), _class)) || _class;