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>
This commit is contained in:
Livia Medeiros authored and GitHub committed 2026-11-25 14:49:11 +00:00
1 parent 2fd4580d4a
commit 0623b0d4c7
4 files changed
+42 -3

No files matched your search

+1 -1
View File
@@ -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;
}
+1 -2
View File
@@ -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;
@@ -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');
+15
View File
@@ -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]');
}
}