5to6 / 5to6-codemod

A collection of codemods that allow you to transform your js code from ES5 to ES6.
https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb
302 stars 36 forks source link

Update no-strict to only replace removed leading comments #25

Closed xzyfer closed 7 years ago

xzyfer commented 7 years ago

Currently the no-strict transform blindly resets the leading comment. This can cause the root comment to be duplicated, when use strict is inside a closure i.e.

/**
 * My comment here
 */
define(function(require) {
    'use strict';
})
/**
 * My comment here
 */
/**
 * My comment here
 */
define(function(require) {});

This patch only resets the leading comment if the use strict is at the root level of the file.

xjamundx commented 7 years ago

Nice check! Any chance you can add a test for it?

xzyfer commented 7 years ago

My bad, added test.

xjamundx commented 7 years ago

Thanks will publish