Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno bundle not bundling imports #9200

Closed
larrybahr opened this issue Jan 20, 2021 · 2 comments · Fixed by #9251
Closed

Deno bundle not bundling imports #9200

larrybahr opened this issue Jan 20, 2021 · 2 comments · Fixed by #9251
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@larrybahr
Copy link

larrybahr commented Jan 20, 2021

When trying to bundle my code for production it looks like some of the required code from the import is being optimized out.
Using deno test all the tests pass and everything works fine. It is just the bundling that is breaking.
I was on 1.7.0 but after seeing #9176 I tried canary with no success.

Here is a simple gist to reproduce https://gist.github.com/larrybahr/0497bf1a419991e681987af505d54800
Gist cleaned up after this was resolved, but here is the code for archiving purposes.

import { isEmail } from "https://deno.land/x/[email protected]/mod.ts";
isEmail("[email protected]");
C:\>deno --version
deno 1.7.0+413f79a (canary, x86_64-pc-windows-msvc)
v8 8.9.255.3
typescript 4.1.3

C:\>deno bundle https://gist.githubusercontent.com/larrybahr/0497bf1a419991e681987af505d54800/raw/4afb6dd4b9cc4b94a9944372ea27608d646d0383/mod.ts
Bundle https://gist.githubusercontent.com/larrybahr/0497bf1a419991e681987af505d54800/raw/4afb6dd4b9cc4b94a9944372ea27608d646d0383/mod.ts
Check https://gist.githubusercontent.com/larrybahr/0497bf1a419991e681987af505d54800/raw/4afb6dd4b9cc4b94a9944372ea27608d646d0383/mod.ts
const includes = (arr, val)=>arr.some((arrVal)=>val === arrVal
    )
;
const alpha = {
    'en-US': /^[A-Z]+$/i,
    'bg-BG': /^[А-Я]+$/i,
    'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
    'da-DK': /^[A-ZÆØÅ]+$/i,
    'de-DE': /^[A-ZÄÖÜß]+$/i,
    'el-GR': /^[Α-ώ]+$/i,
    'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
    'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
    'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
    'nb-NO': /^[A-ZÆØÅ]+$/i,
    'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
    'nn-NO': /^[A-ZÆØÅ]+$/i,
    'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
    'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
    'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
    'ru-RU': /^[А-ЯЁ]+$/i,
    'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
    'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
    'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
    'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i,
    'sv-SE': /^[A-ZÅÄÖ]+$/i,
    'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
    'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
    'vi-VN': /^[A-ZÀÁÃÂĂĐÈÉÊÌÍĨÒÓÕÔƠÙÚŨƯÝ]+$/i,
    'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
    ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
    he: /^[א-ת]+$/,
    fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i
};
const alphanumeric = {
    'en-US': /^[0-9A-Z]+$/i,
    'bg-BG': /^[0-9А-Я]+$/i,
    'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
    'da-DK': /^[0-9A-ZÆØÅ]+$/i,
    'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
    'el-GR': /^[0-9Α-ω]+$/i,
    'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
    'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
    'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
    'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
    'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
    'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
    'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
    'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
    'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
    'ru-RU': /^[0-9А-ЯЁ]+$/i,
    'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
    'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
    'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
    'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
    'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
    'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
    'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
    'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
    'vi-VN': /^[0-9A-ZÀÁÃÂĂĐÈÉÊÌÍĨÒÓÕÔƠÙÚŨƯÝ]+$/i,
    ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
    he: /^[0-9א-ת]+$/,
    fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i
};
const decimal = {
    'en-US': '.',
    ar: '٫',
    fa: '٫'
};
const englishLocales = [
    'AU',
    'GB',
    'HK',
    'IN',
    'NZ',
    'ZA',
    'ZM'
];
for(let locale, i = 0; i < englishLocales.length; i++){
    locale = `en-${englishLocales[i]}`;
    alpha[locale] = alpha['en-US'];
    alphanumeric[locale] = alphanumeric['en-US'];
    decimal[locale] = decimal['en-US'];
}
const arabicLocales = [
    'AE',
    'BH',
    'DZ',
    'EG',
    'IQ',
    'JO',
    'KW',
    'LB',
    'LY',
    'MA',
    'QM',
    'QA',
    'SA',
    'SD',
    'SY',
    'TN',
    'YE',
];
for(let locale1, i1 = 0; i1 < arabicLocales.length; i1++){
    locale1 = `ar-${arabicLocales[i1]}`;
    alpha[locale1] = alpha.ar;
    alphanumeric[locale1] = alphanumeric.ar;
    decimal[locale1] = decimal.ar;
}
const farsiLocales = [
    'IR',
    'AF'
];
for(let locale2, i2 = 0; i2 < farsiLocales.length; i2++){
    locale2 = `fa-${farsiLocales[i2]}`;
    alpha[locale2] = alpha.fa;
    alphanumeric[locale2] = alphanumeric.fa;
    decimal[locale2] = decimal.fa;
}
const dotDecimal = [
    'ar-EG',
    'ar-LB',
    'ar-LY'
];
const commaDecimal = [
    'bg-BG',
    'cs-CZ',
    'da-DK',
    'de-DE',
    'el-GR',
    'en-ZM',
    'es-ES',
    'fr-FR',
    'it-IT',
    'ku-IQ',
    'hu-HU',
    'nb-NO',
    'nn-NO',
    'nl-NL',
    'pl-PL',
    'pt-PT',
    'ru-RU',
    'sl-SI',
    'sr-RS@latin',
    'sr-RS',
    'sv-SE',
    'tr-TR',
    'uk-UA',
    'vi-VN',
];
for(let i3 = 0; i3 < dotDecimal.length; i3++){
    decimal[dotDecimal[i3]] = decimal['en-US'];
}
for(let i4 = 0; i4 < commaDecimal.length; i4++){
    decimal[commaDecimal[i4]] = ',';
}
alpha['pt-BR'] = alpha['pt-PT'];
alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
decimal['pt-BR'] = decimal['pt-PT'];
alpha['pl-Pl'] = alpha['pl-PL'];
alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
decimal['pl-Pl'] = decimal['pl-PL'];
const assertString = (input)=>{
    const isString = typeof input === 'string';
    if (!isString) {
        throw new TypeError(`Expected a string but received ${typeof input}.`);
    }
};
const toDate = (str)=>{
    assertString(str);
    const date = Date.parse(str);
    return !isNaN(date) ? new Date(date) : null;
};
isEmail("[email protected]");

Running the code in browser results in
image

@kitsonk kitsonk added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Jan 21, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Jan 21, 2021

cc/ @kdy1

kdy1 added a commit to kdy1/swc that referenced this issue Jan 21, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jan 21, 2021
kdy1 added a commit to swc-project/swc that referenced this issue Jan 25, 2021
swc_bundler:
 - Fix deglobbing of imports. (denoland/deno#8985)
 - Use correct syntax context while deglobbing imports. (denoland/deno#9212)
 - Allow reexporting from wrapped esms. (denoland/deno#8959, denoland/deno#9200)
 - Fix statement orderings. (denoland/deno#9250)
 - Emit injected items as early as possible. (denoland/deno#9250)
 - Respect `external_modules`. (#1338)
 - Fix cjs suppport. (#1328)

swc_ecma_transforms_base:
 - hygiene: Fix for hoisting. (denoland/deno#9212)
@larrybahr
Copy link
Author

The issue is resolved! Thank you for your hard work to get this fixed quickly!

For anyone else that would like to use the fix now
deno upgrade --canary --version=40fc5f55ea582755d221a3445a2f5f388845bc23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants