mxmul / closure-loader

Webpack loader for Google Closure modules ✨
MIT License
29 stars 22 forks source link

Incorrectly finds `goog.require` and `goog.provide` statements in comments #16

Open tlrobinson opened 8 years ago

tlrobinson commented 8 years ago

The simple regex approach incorrectly finds goog.require and goog.provides statements that are within JavaScript comments, which can break compilation in certain situations.

eXaminator commented 8 years ago

Hi, thanks for the info and good point. I'll have to think about this a while. Any suggestions. I could try parsing files with babylon or acorn or something similar, but I guess that would be slower and might fail on files that contain syntax errors. Also I don't know anything about JS parsers yet so it would probably take a lot of time I don't have right now.

I will leave this open for now and might come back to it later. But PRs are welcome.

jdb8 commented 8 years ago

Something I did during my experiments to get the loader working for 'goog:foo.bar.baz' style imports (#12) was to enforce start-of-line in the regex, and add the multiline flag: https://github.com/jdb8/closure-loader/commit/3408c009533f0000f88f1ebf0c4b99607468d71c

I'm going to go clean this up (since this probably still misses some stuff, and the /g flag might not be necessary), but this seems robust enough at least for my needs.

giuseppeg commented 8 years ago

You could strip out the comments at matching time. Here's how facebook does it https://github.com/facebook/node-haste/blob/master/src/lib/extractRequires.js

lexoyo commented 5 years ago

hello @jdb8 it's a good fix, why not make a PR?

lexoyo commented 5 years ago

says a guy 3 years later :cry: