Open tlrobinson opened 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.
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.
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
hello @jdb8 it's a good fix, why not make a PR?
says a guy 3 years later :cry:
The simple regex approach incorrectly finds
goog.require
andgoog.provides
statements that are within JavaScript comments, which can break compilation in certain situations.