bublejs / bublejs/buble

Function declarations within blocks are transpiled into code that breaks on some pre-ES2015 targets

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

Description

Prior to ES2015, function declarations within blocks were forbidden in strict mode (See [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block)):

```
(function() {
'use strict';
if (1) {
function x() {
// This results in "Strict mode does not allow function declarations in a
// lexically nested statement" or a similar error in some older browsers
}
}
})();
```

(Sorry, I didn't have the weapons to test this myself, just consulted the and trust my colleague's report.)

We ran into this issue when we saw some some buble-transformed code crash on iOS 9 Safari.

Would it be within Bublé's scope to transform this into equivalent code that works? E.g.:

```
(function() {
'use strict';
if (1) {
var x = function x() {
// Tada!
}
}
})();
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the strict-mode example on an affected pre-ES2015 target, then trace Bublé's handling of function declarations inside blocks. Compare the generated output with the issue's proposed equivalent and verify that it runs on iOS 9 Safari or a comparable older target without the reported syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.