Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Regex does not recognize if SourceMappingURL content is within a string #5

Open
Koiix opened this issue Sep 15, 2020 · 2 comments
Open

Comments

@Koiix
Copy link

Koiix commented Sep 15, 2020

For example, if we had:
const sourceMappingURL = require('source-map-url');
const code = 'console.log("//# sourceMappingURL=index.js.map")';
sourceMappingURL.removeFrom(code);
There is no SourceMappingURL comment in the piece of code, but the current build would remove the string contents in the code segment.

@Koiix
Copy link
Author

Koiix commented Sep 15, 2020

A candidate replacement regex might be:
/(?:\/\*(?:\s*(?:\/\/)?)?(?:[#@] sourceMappingURL=([^\s'"]*))\s*\*\/|\/\/(?:[#@] sourceMappingURL=([^\s'"]*)))\s*(?=([^"']*"[^'"]*")*[^'"]*$)(?=([^"']*"[^'"]*")*[^'"]*$)/

@lydell
Copy link
Owner

lydell commented Sep 15, 2020

Hi! I’d recommend not using this package. Here are some alternatives:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants