justmoon / node-extend

Simple function to extend objects
MIT License
341 stars 68 forks source link

use strict mode should be at the root of the module #32

Closed greelgorke closed 9 years ago

greelgorke commented 9 years ago

because a module code is basically a function body

solves #31

greelgorke commented 9 years ago

i see the build is failing because of the eslint rule no-extra-strict

i would suggest, that we should remove the struct pramas from the inner functions, because the module-wide one should cover it.

the rule itself is depricated btw.

ljharb commented 9 years ago

The concern is that this file is occasionally just ran in the global scope - not always as a module. That's the reason I only strict moded the individual functions.

I don't understand why this should make a difference though, since none of the functionality of the file relies on either strict or sloppy behavior?

greelgorke commented 9 years ago

its run in global scope? it is a a node module and supposed to be used as such right? node.js modules are basicaly function bodies, they should be wrapped into such by the loaders. if someone uses it without the loader or any kind of wrapper, than it's basically a misuse case.

the issue as in the referenced one, is that some loaders are using eval (like webpack) for some tasks. in webpacks case its a source maps support feature. and somehow eval and lack of the module-wide pragma is causing the ReferenceErrors.

i don't know why this is an issue. here is a related issue https://code.google.com/p/chromium/issues/detail?id=491536 that indicates it to be a bug in v8, so this PR would be mor of a workaround of this bug.

for solving the problem we could wrap the module in a function explicitly so the global-scope usecase will be covered. would this be a solution?

ljharb commented 9 years ago

Yeah, that's a fair point. I'm OK not supporting non-browserify-ish use cases.

I'll consider this a breaking change, just in case, but I think it's a good one.

greelgorke commented 9 years ago

thank you :)