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

Tagged templates in different files overwrite each other when executed in the same scope #239

Open
papandreou opened this issue Dec 28, 2019 · 0 comments
Labels

Comments

@papandreou
Copy link

Given a setup like this:

foo.js

function hey([str]) {
  return str;
}

function bar() {
  console.log(hey`foo`);
}

bar.js

function hey([str]) {
  return str;
}

function foo() {
  console.log(hey`bar`);
}

index.html

<script src="foo.js"></script>
<script src="bar.js"></script>
<script>
  foo();
  bar();
</script>

Running the above in a browser outputs:

foo
bar

After running it through buble --yes dangerousTaggedTemplateString sourcedir -o targetdir it outputs:

bar
bar

This happens because both transpiled files put the quasis into global variables called templateObject, which then overwrite each other. I think this is what was pointed out on the original PR here: #67 (comment)

In general I would assume that the "compile directory" mode of buble would avoid introducing colliding identifiers in the root scope across all the files. I think using this mode to transpile a bunch of test files for execution in a browser is a very common use case? Maybe the root scope object could just be carried over to the subsequent files so the var would come out as templateObject$1 in the second file?

Babel has the same bug btw. :)

@mourner mourner added the bug label Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants