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

Flask Bundle remove white space after variables enclosed in ${} in Template strings in JavaScript #157

Open
Rongeegee opened this issue Jun 8, 2023 · 0 comments

Comments

@Rongeegee
Copy link

Rongeegee commented Jun 8, 2023

So in my production environment, i use Bundle imported from flask_assets.

from flask_assets import Environment, Bundle

JS_BUNDLE = Bundle('js/modules/xxxxx.js',......,'js/modules/xxxxx.js',
                   filters=filters, output='js/bundle/scripts.custom.%s.min.js' % RELEASE_VERSION)

assets = Environment(app)
assets.register('js_custom', JS_BUNDLE)

Then in my JavaScript file, I have the following

const date = new Date();

const day = date.getDate() >= 10 ? date.getDate() :  "0" + date.getDate() ;
const month = date.toLocaleString('default', { month: 'long' }).substring(0,3);
const year = date.getFullYear();

const englishDate = `${day} ${month}, ${year}`;

Suppose that today's date is 6/8/2023. The englishDate is supposed to have a string value of "08 Jun, 2023". However, the value it got on production after the bundle is "08Jun,2023". All the spaces within the string is removed.

I checked the bundled file, it turned out that the spaces are remove in the code when being bundled. The last line became

const englishDate = `${day}${month},${year}`;

However, If I don't use variables inside the string enclosed by backticks (`). Such as

const englishDate = `June 8th,  2023`;

All the spaces in the string will be preserved.

It seems like this issue only happened when a variable is used within a template string. All the spaces followed by the variable will be removed by the bundler.

Can anyone replicate it and let me know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant