[Transforms] fix _this = this capture emitted before "use strict" directives in AMD module output #7953
Conversation
| } | ||
|
|
||
| target.push(source[i]); | ||
| target.unshift(source[i]); |
There was a problem hiding this comment.
Doesn't this reverse all your prologues?
There was a problem hiding this comment.
it will put the prologues as the first statement in the result array. I use unshift here because there is no guarantee in the order of this function when it gets call.
There was a problem hiding this comment.
Right, but if you have existing 3 prologues, they'll be reversed.
var x = [];
[1,2,3].forEach(e => x.unshift(e))x will have [3, 2, 1].
This function should only be getting called when adding to the beginning of an empty array anyway, so just document that and add an assertion if that's your concern.
There was a problem hiding this comment.
I see what you mean now. But there are the same and it will not matter right? also if the prologue is sprinkle around the body function, it will be aggregate to the top so that should be ok as well?
The function is not necessary call at the beginning of an empty array. Like below the target statements-array may not be empty
There was a problem hiding this comment.
But prologues need to go at the beginning, so what situations will you have where you're adding prologues other than to the beginning of the array? Any time this function gets called after anything, that's probably a bad sign.
But there are the same and it will not matter right?
Apart from preserving what the user wrote the best we can, that's unfortunately not necessarily true. From the spec:
Implementations may define implementation specific meanings for ExpressionStatement productions which are not a Use Strict Directive and which occur in a Directive Prologue.
So you don't actually know what your engine will want to do for some prologues and whether they are order-dependent. For instance, there used to be uncertainty on whether the "use asm directive should be allowed to come before a "use strict". https://bugzilla.mozilla.org/show_bug.cgi?id=877908
… the first statement in the result statements array
_this = this capture emitted before "use strict" directives in AMD module output
|
👍 |
|
|
||
| /** | ||
| * Add any necessary prologue-directives into target statement-array. | ||
| * The function needs to be called during each transformation steps. |
There was a problem hiding this comment.
*step
Also, you should probably modified the comment to mention that it needs to be called whenever we transform the statement list of a source file, namespace, or function-like body.
|
👍 |
1 similar comment
|
👍 |
Fix issue #7913