@amplitude/ampli
Version:
Amplitude CLI
43 lines (42 loc) • 1.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const state_1 = require("./state");
class StringLiteral extends state_1.State {
constructor(source, prefix, postfix, skip, multiline) {
super('string', source, prefix.length);
this.prefix = prefix;
this.postfix = postfix;
this.skip = skip;
this.multiline = multiline;
}
visit(fromIndex) {
if (this.isPrefix(this.postfix, fromIndex)) {
this.length += this.postfix.length;
return undefined;
}
for (let i = 0; i < this.skip.length; i += 1) {
if (this.isPrefix(this.skip[i], fromIndex)) {
this.length += this.skip[i].length;
return this;
}
}
if (!this.multiline) {
if (this.source[fromIndex] === '\n' || this.source[fromIndex] === '\r') {
return undefined;
}
}
this.length += 1;
return this;
}
}
class StringLiteralFactory extends state_1.StateFactory {
constructor(source, prefix, postfix, skip, multiline) {
super(source, prefix, postfix);
this.multiline = multiline;
this.skip = skip.map(s => [...s]);
}
createState() {
return new StringLiteral(this.source, this.prefix, this.postfix, this.skip, this.multiline);
}
}
exports.default = StringLiteralFactory;