bublejs / bublejs/buble

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

Open
#239 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
874
Forks
62
PR merge metrics
No merged PRs in 30d

Description

Given a setup like this:

## foo.js

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

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

## bar.js

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

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

## index.html

```html

foo();
bar();

```

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: https://github.com/bublejs/buble/pull/67#issuecomment-349340228

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. :)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.