8000 Merge pull request #4524 from sjrd/no-require-es2018-in-linker-interf… · renowncoder/scala-js@08de1e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 08de1e3

Browse files
authored
Merge pull request scala-js#4524 from sjrd/no-require-es2018-in-linker-interface-js
Avoid using the (?m) flag in the regexes in linker-interface.
2 parents 3c58b2c + 8ab8eab commit 08de1e3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

linker-interface/shared/src/main/scala/org/scalajs/linker/interface/ReportToLinkerOutputAdapter.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ object ReportToLinkerOutputAdapter {
151151
}
152152
}
153153

154-
private val sourceMapRe = """(?m)^//# sourceMappingURL=.*$""".r
154+
/* This regex would normally be written with the (?m) flag, but that would
155+
* require ES2018, so we work around it.
156+
*/
157+
private val sourceMapRe = """(?:^|\n)(//# sourceMappingURL=[^\n]*)(?:\n|$)""".r
155158

156159
/** Patches the JS file content to have the provided source map link (or none)
157160
*
@@ -170,14 +173,14 @@ object ReportToLinkerOutputAdapter {
170173
} { reMatch =>
171174
val res = new StringBuilder
172175

173-
res.append(reMatch.before)
176+
res.append(reMatch.before(1))
174177

175178
/* If there is no source map link, keep an empty line to not break a
176179
* potential (unlinked) source map
177180
*/
178181
newLine.foreach(res.append(_))
179182

180-
res.append(reMatch.after)
183+
res.append(reMatch.after(1))
181184

182185
res.toString()
183186
}
@@ -193,7 +196,7 @@ object ReportToLinkerOutputAdapter {
193196
* So as a legacy mechanism, this is OK-ish. It keeps us from having to build
194197
* the infrastructure to parse JSON cross platform.
195198
*/
196-
private val fileFieldRe = """(?m)([,{])\s*"file"\s*:\s*".*"\s*([,}])""".r
199+
private val fileFieldRe = """([,{])\s*"file"\s*:\s*"[^"]*"\s*([,}])""".r
197200

198201
/** Patches the source map content to have the provided JS file link (or none).
199202
*

project/Build.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,6 @@ object Build {
869869

870870
fileSet.toSeq.filter(_.getPath().endsWith(".scala"))
871871
}.taskValue,
872-
873-
// Required for the regex (?m) flag in ReportToLinkerOutputAdapter.scala
874-
scalaJSLinkerConfig ~= { _.withESFeatures(_.withESVersion(ESVersion.ES2018)) },
875872
).withScalaJSCompiler.withScalaJSJUnitPlugin.dependsOn(
876873
library, irProjectJS, jUnitRuntime % "test", testBridge % "test", jUnitAsyncJS % "test",
877874
)
@@ -1046,9 +1043,6 @@ object Build {
10461043
}.taskValue,
10471044
},
10481045

1049-
// Required for the regex (?m) flag in ReportToLinkerOutputAdapter.scala
1050-
scalaJSLinkerConfig ~= { _.withESFeatures(_.withESVersion(ESVersion.ES2018)) },
1051-
10521046
scalaJSLinkerConfig in Test ~= (_.withModuleKind(ModuleKind.CommonJSModule))
10531047
).withScalaJSCompiler.withScalaJSJUnitPlugin.dependsOn(
10541048
linkerInterfaceJS, library, irProjectJS, jUnitRuntime % "test", testBridge % "test", jUnitAsyncJS % "test"

0 commit comments

Comments
 (0)
0