Commit 0623b0d4c72 for nodejs
commit 0623b0d4c72813e714ea5dccf805f98760ed0caa
Author: Livia Medeiros <livia@cirno.name>
Date: Wed Nov 25 22:49:11 2026 +0800
lib: recognize `<LS>` and `<PS>` as line terminators
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67695
Refs: https://tc39.es/ecma262/#sec-line-terminators
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
diff --git a/lib/internal/source_map/source_map_cache.js b/lib/internal/source_map/source_map_cache.js
index e1fa55c5cab..f48842bf22c 100644
--- a/lib/internal/source_map/source_map_cache.js
+++ b/lib/internal/source_map/source_map_cache.js
@@ -484,7 +484,7 @@ function getSourceLine(
if (typeof source !== 'string') {
return;
}
- const lines = RegExpPrototypeSymbolSplit(/\r?\n/, source, originalLine + 1);
+ const lines = RegExpPrototypeSymbolSplit(/\r?\n|[\u2028\u2029]/, source, originalLine + 1);
const line = lines[originalLine];
return line;
}
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 3128d5e5030..dff7c0bcdf3 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -254,8 +254,7 @@ const numberRegExp = /^(0|[1-9][0-9]*)$/;
const coreModuleRegExp = /^ {4}at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/;
const classRegExp = /^(\s+[^(]*?)\s*{/;
-// eslint-disable-next-line node-core/no-unescaped-regexp-dot
-const stripCommentsRegExp = /(\/\/.*?\n)|(\/\*(.|\n)*?\*\/)/g;
+const stripCommentsRegExp = /(\/\/[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029])|\/\*(?s:.*?)\*\/)/g;
const kMinLineLength = 16;
diff --git a/test/parallel/test-source-map-line-terminators.js b/test/parallel/test-source-map-line-terminators.js
new file mode 100644
index 00000000000..74445419316
--- /dev/null
+++ b/test/parallel/test-source-map-line-terminators.js
@@ -0,0 +1,25 @@
+// Flags: --expose-internals
+'use strict';
+
+require('../common');
+const assert = require('node:assert');
+const { SourceMap } = require('internal/source_map/source_map');
+const { getSourceLine } = require('internal/source_map/source_map_cache');
+
+// LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) must be recognized as line terminators
+const source = 'first\u2028second\u2029third\nfourth';
+
+const sourceMap = new SourceMap({
+ version: 3,
+ sources: ['file:///blep.js'],
+ sourcesContent: [source],
+ names: [],
+ mappings: '',
+});
+
+const sourcePath = sourceMap.payload.sources[0];
+
+assert.strictEqual(getSourceLine(sourceMap, sourcePath, 0), 'first');
+assert.strictEqual(getSourceLine(sourceMap, sourcePath, 1), 'second');
+assert.strictEqual(getSourceLine(sourceMap, sourcePath, 2), 'third');
+assert.strictEqual(getSourceLine(sourceMap, sourcePath, 3), 'fourth');
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index 4e26661a4b4..d4c9be5dbfd 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -4107,3 +4107,18 @@ ${error.stack.split('\n').slice(1).join('\n')}`,
assert.strictEqual(inspect(new Class()), 'Namespaced.Class {}');
assert.strictEqual(inspect(new DerivedClass()), 'DerivedClass [Namespaced.Class] {}');
}
+
+// LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) must be recognized as line terminators
+{
+ for (const lineTerminator of ['\u2028', '\u2029']) {
+ const blockCommentClass = vm.runInThisContext(
+ `(class Blep /* (${lineTerminator}) */ {})`,
+ );
+ const lineCommentClass = vm.runInThisContext(
+ `(class Blop // (${lineTerminator}{})`,
+ );
+
+ assert.strictEqual(inspect(blockCommentClass), '[class Blep]');
+ assert.strictEqual(inspect(lineCommentClass), '[class Blop]');
+ }
+}