UNPKG

@amplitude/ampli

Version:

Amplitude CLI

43 lines (42 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const state_1 = require("./state"); class CodeState extends state_1.State { constructor(source, codeFactory) { super('code', source, 0); this.codeFactory = codeFactory; } visit(fromIndex) { const factory = this.findBestFactory(fromIndex); if (factory !== undefined) { return factory.createState(); } this.length += 1; return this; } findBestFactory(fromIndex) { let bestFactory; let bestPrefixLength = 0; this.codeFactory.factories.forEach(factory => { const prefixLength = factory.test(fromIndex); if (prefixLength > bestPrefixLength) { bestFactory = factory; bestPrefixLength = prefixLength; } }); return bestFactory; } } class CodeStateFactory extends state_1.StateFactory { constructor(source, factories) { super(source, '', ''); this.factories = factories; } test() { return 0; } createState() { return new CodeState(this.source, this); } } exports.default = CodeStateFactory;