word-wrap icon indicating copy to clipboard operation
word-wrap copied to clipboard

revert compatibility

Open lamweili opened this issue 2 years ago • 10 comments

In commit 9f626935f3fac6ec0f3c4b26baea4eb9740d9645, let was used. https://github.com/jonschlinkert/word-wrap/blob/207044ebda1dd3809d15b6000a48409266536771/index.js#L9-L10

However, the package.json specifies "node": ">=0.10.0" compatibility. https://github.com/jonschlinkert/word-wrap/blob/207044ebda1dd3809d15b6000a48409266536771/package.json#L28

This resulted in the following errors for older Node.js:

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Thus, we should change let to var to maintain compatibility for ^1.x.x in adherence to semver. If compatibility needs to be upgraded, it should be the next major semver (^2.x.x) release.

lamweili avatar Jul 25 '23 05:07 lamweili

Thanks @lamweili . Should const also be replaced?

doowb avatar Jul 25 '23 14:07 doowb

@doowb, const is good according to node.green. My GitHub actions, which test older Node.js (v4) for compatibility issues, didn't flag any errors.

lamweili avatar Jul 25 '23 15:07 lamweili

@lamweili Thanks! Have the same issue with node v4

DmitryZ-outten avatar Jul 26 '23 15:07 DmitryZ-outten

I'm having a problem with let on node 4 as well:

21:12:26    let lastCharPos = str.length - 1;
21:12:26    ^^^
21:12:26  
21:12:26  SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

If I edit index.js by hand after installing and add 'use strict'; at the beginning of the file then I don't get this error.

bahamat avatar Jul 27 '23 02:07 bahamat

Although we might not use word-wrap explicitly, it is used by dependencies such as eslint. (eslint@>=2 <=7.0.0-alpha.3 > optionator@^0.8 > word-wrap@~1.2.3)

Editing the index.js by hand is a workaround but might be overridden by npm.

It will be good to quickly patch it back to restore compatibility instead of all dependencies changing major semver.

lamweili avatar Jul 27 '23 02:07 lamweili

Can confirm, I'm hitting this because of eslint.

bahamat avatar Jul 27 '23 02:07 bahamat

For clarification, I wasn’t suggesting editing index.js as a workaround. But if the maintainer wants to keep let, then use strict might be an alternative.

bahamat avatar Jul 27 '23 08:07 bahamat

@doowb, any chance of merging and releasing it soon?

lamweili avatar Aug 03 '23 15:08 lamweili

It seems like @doowb is busy. How about @jonschlinkert?

lamweili avatar Aug 11 '23 14:08 lamweili

Bump! @doowb @jonschlinkert

lamweili avatar Apr 05 '24 00:04 lamweili