Processors to esm
This commit is contained in:
parent
e0873b359c
commit
cdf251f9cc
|
@ -1,6 +1,6 @@
|
||||||
const { FIND_HBS_REGEX } = require("../utilities")
|
import { FIND_HBS_REGEX } from "../utilities"
|
||||||
const preprocessor = require("./preprocessor")
|
import * as preprocessor from "./preprocessor"
|
||||||
const postprocessor = require("./postprocessor")
|
import * as postprocessor from "./postprocessor"
|
||||||
|
|
||||||
function process(output, processors, opts) {
|
function process(output, processors, opts) {
|
||||||
for (let processor of processors) {
|
for (let processor of processors) {
|
||||||
|
@ -21,7 +21,7 @@ function process(output, processors, opts) {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.preprocess = (string, opts) => {
|
export function preprocess(string, opts) {
|
||||||
let processors = preprocessor.processors
|
let processors = preprocessor.processors
|
||||||
if (opts.noFinalise) {
|
if (opts.noFinalise) {
|
||||||
processors = processors.filter(
|
processors = processors.filter(
|
||||||
|
@ -30,7 +30,7 @@ module.exports.preprocess = (string, opts) => {
|
||||||
}
|
}
|
||||||
return process(string, processors, opts)
|
return process(string, processors, opts)
|
||||||
}
|
}
|
||||||
module.exports.postprocess = string => {
|
export function postprocess(string) {
|
||||||
let processors = postprocessor.processors
|
let processors = postprocessor.processors
|
||||||
return process(string, processors)
|
return process(string, processors)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { LITERAL_MARKER } = require("../helpers/constants")
|
import { LITERAL_MARKER } from "../helpers/constants"
|
||||||
|
|
||||||
const PostProcessorNames = {
|
export const PostProcessorNames = {
|
||||||
CONVERT_LITERALS: "convert-literals",
|
CONVERT_LITERALS: "convert-literals",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,7 @@ class Postprocessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.PostProcessorNames = PostProcessorNames
|
export const processors = [
|
||||||
|
|
||||||
module.exports.processors = [
|
|
||||||
new Postprocessor(PostProcessorNames.CONVERT_LITERALS, statement => {
|
new Postprocessor(PostProcessorNames.CONVERT_LITERALS, statement => {
|
||||||
if (typeof statement !== "string" || !statement.includes(LITERAL_MARKER)) {
|
if (typeof statement !== "string" || !statement.includes(LITERAL_MARKER)) {
|
||||||
return statement
|
return statement
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
const { HelperNames } = require("../helpers")
|
import { HelperNames } from "../helpers"
|
||||||
const { swapStrings, isAlphaNumeric } = require("../utilities")
|
import { swapStrings, isAlphaNumeric } from "../utilities"
|
||||||
|
|
||||||
const FUNCTION_CASES = ["#", "else", "/"]
|
const FUNCTION_CASES = ["#", "else", "/"]
|
||||||
|
|
||||||
const PreprocessorNames = {
|
export const PreprocessorNames = {
|
||||||
SWAP_TO_DOT: "swap-to-dot-notation",
|
SWAP_TO_DOT: "swap-to-dot-notation",
|
||||||
FIX_FUNCTIONS: "fix-functions",
|
FIX_FUNCTIONS: "fix-functions",
|
||||||
FINALISE: "finalise",
|
FINALISE: "finalise",
|
||||||
|
@ -23,7 +23,7 @@ class Preprocessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.processors = [
|
export const processors = [
|
||||||
new Preprocessor(PreprocessorNames.SWAP_TO_DOT, statement => {
|
new Preprocessor(PreprocessorNames.SWAP_TO_DOT, statement => {
|
||||||
let startBraceIdx = statement.indexOf("[")
|
let startBraceIdx = statement.indexOf("[")
|
||||||
let lastIdx = 0
|
let lastIdx = 0
|
||||||
|
@ -74,5 +74,3 @@ module.exports.processors = [
|
||||||
return `{{ all ${insideStatement} }}`
|
return `{{ all ${insideStatement} }}`
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
|
|
||||||
module.exports.PreprocessorNames = PreprocessorNames
|
|
||||||
|
|
Loading…
Reference in New Issue