@philpl/buble
Version:
The blazing fast, batteries-included ES2015 compiler
35 lines (30 loc) • 777 B
JavaScript
import Node from '../Node.js';
import CompileError from '../../utils/CompileError.js';
const nonAsciiLsOrPs = /[\u2028-\u2029]/g;
export default class Literal extends Node {
initialise() {
if (typeof this.value === 'string') {
this.program.indentExclusionElements.push(this);
}
}
transpile(code, transforms) {
if (transforms.numericLiteral) {
if (this.raw.match(/^0[bo]/i)) {
code.overwrite(this.start, this.end, String(this.value), {
storeName: true,
contentOnly: true
});
}
}
if (typeof this.value === "string" && this.value.match(nonAsciiLsOrPs)) {
code.overwrite(
this.start,
this.end,
this.raw.replace(nonAsciiLsOrPs, m => m == '\u2028' ? '\\u2028' : '\\u2029'),
{
contentOnly: true
}
);
}
}
}