| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 945aa74 commit a2eb55a
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,8 +41,8 @@ const esmSourceMapCache = new SafeMap(); | |||
| 41 | 41 | // The generated sources is not mutable, so we can use a Map without memory concerns: | |
| 42 | 42 | const generatedSourceMapCache = new SafeMap(); | |
| 43 | 43 | const kLeadingProtocol = /^\w+:\/\//; | |
| 44 | - const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?<sourceMappingURL>[^\s]+)/; | ||
| 45 | - const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?<sourceURL>[^\s]+)/; | ||
| 44 | + const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?<sourceMappingURL>[^\s]+)/g; | ||
| 45 | + const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?<sourceURL>[^\s]+)/g; | ||
| 46 | 46 | ||
| 47 | 47 | const { fileURLToPath, pathToFileURL, URL } = require('internal/url'); | |
| 48 | 48 | let SourceMap; | |
@@ -80,11 +80,14 @@ function setSourceMapsEnabled(val) { | |||
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | 82 | function extractSourceURLMagicComment(content) { | |
| 83 | - const matchSourceURL = RegExpPrototypeExec( | ||
| 84 | - kSourceURLMagicComment, | ||
| 85 | - content | ||
| 86 | - ); | ||
| 87 | - if (matchSourceURL === null) { | ||
| 83 | + let match; | ||
| 84 | + let matchSourceURL; | ||
| 85 | + // A while loop is used here to get the last occurrence of sourceURL. | ||
| 86 | + // This is needed so that we don't match sourceURL in string literals. | ||
| 87 | + while ((match = RegExpPrototypeExec(kSourceURLMagicComment, content))) { | ||
| 88 | + matchSourceURL = match; | ||
| 89 | + } | ||
| 90 | + if (matchSourceURL == null) { | ||
| 88 | 91 | return null; | |
| 89 | 92 | } | |
| 90 | 93 | let sourceURL = matchSourceURL.groups.sourceURL; | |
@@ -104,13 +107,21 @@ function maybeCacheSourceMap(filename, content, cjsModuleInstance, isGeneratedSo | |||
| 104 | 107 | debug(err); | |
| 105 | 108 | return; | |
| 106 | 109 | } | |
| 107 | - const match = RegExpPrototypeExec(kSourceMappingURLMagicComment, content); | ||
| 110 | + | ||
| 111 | + let match; | ||
| 112 | + let lastMatch; | ||
| 113 | + // A while loop is used here to get the last occurrence of sourceMappingURL. | ||
| 114 | + // This is needed so that we don't match sourceMappingURL in string literals. | ||
| 115 | + while ((match = RegExpPrototypeExec(kSourceMappingURLMagicComment, content))) { | ||
| 116 | + lastMatch = match; | ||
| 117 | + } | ||
| 118 | + | ||
| 108 | 119 | if (sourceURL === undefined) { | |
| 109 | 120 | sourceURL = extractSourceURLMagicComment(content); | |
| 110 | 121 | } | |
| 111 | - if (match) { | ||
| 112 | - const data = dataFromUrl(filename, match.groups.sourceMappingURL); | ||
| 113 | - const url = data ? null : match.groups.sourceMappingURL; | ||
| 122 | + if (lastMatch) { | ||
| 123 | + const data = dataFromUrl(filename, lastMatch.groups.sourceMappingURL); | ||
| 124 | + const url = data ? null : lastMatch.groups.sourceMappingURL; | ||
| 114 | 125 | if (cjsModuleInstance) { | |
| 115 | 126 | cjsSourceMapCache.set(cjsModuleInstance, { | |
| 116 | 127 | filename, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,13 @@ | |||
| 1 | + // Flags: --enable-source-maps | ||
| 2 | + | ||
| 3 | + 'use strict'; | ||
| 4 | + require('../common'); | ||
| 5 | + Error.stackTraceLimit = 2; | ||
| 6 | + | ||
| 7 | + try { | ||
| 8 | + require('../fixtures/source-map/typescript-sourcemapping_url_string'); | ||
| 9 | + } catch (err) { | ||
| 10 | + setTimeout(() => { | ||
| 11 | + console.info(err); | ||
| 12 | + }, 10); | ||
| 13 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Error: an exception. | ||
| 2 | + at *typescript-sourcemapping_url_string.ts:3:7* | ||
| 3 | + at Module._compile (node:internal/modules/cjs/loader:*) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments