@scaffdog/engine
Advanced tools
Comparing version 1.2.0 to 1.2.1-canary.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -32,2 +36,6 @@ if (k2 === undefined) k2 = k; | ||
/** | ||
* internal | ||
*/ | ||
const splitLines = (v) => v.split(/\r?\n/); | ||
/** | ||
* string utils | ||
@@ -46,2 +54,30 @@ */ | ||
exports.helpers.set('rtrim', (_, v) => v.trimEnd()); | ||
exports.helpers.set('head', (_, v, n, offset) => { | ||
const lines = splitLines(v); | ||
const off = offset !== null && offset !== void 0 ? offset : 0; | ||
if (typeof n === 'string') { | ||
const regexp = new RegExp(n); | ||
for (let i = 0; i < lines.length; i++) { | ||
if (regexp.test(lines[i])) { | ||
return lines.slice(0, i + 1 + off).join('\n'); | ||
} | ||
} | ||
return v; | ||
} | ||
return lines.slice(0, n + off).join('\n'); | ||
}); | ||
exports.helpers.set('tail', (_, v, n, offset) => { | ||
const lines = splitLines(v); | ||
const off = (offset !== null && offset !== void 0 ? offset : 0) * -1; | ||
if (typeof n === 'string') { | ||
const regexp = new RegExp(n); | ||
for (let i = lines.length - 1; i >= 0; i--) { | ||
if (regexp.test(lines[i])) { | ||
return lines.slice(lines.length - i + 1 + off).join('\n'); | ||
} | ||
} | ||
return v; | ||
} | ||
return lines.slice(lines.length - n + off).join('\n'); | ||
}); | ||
/** | ||
@@ -48,0 +84,0 @@ * date |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -6,2 +6,2 @@ import type { TagPair } from '@scaffdog/types'; | ||
}; | ||
export declare const tokenize: (input: string, options?: Partial<TokenizeOptions> | undefined) => AnyToken[]; | ||
export declare const tokenize: (input: string, options?: Partial<TokenizeOptions>) => AnyToken[]; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -188,4 +192,7 @@ if (k2 === undefined) k2 = k; | ||
let bufPos = null; | ||
let inTag = false; | ||
let i = 0; | ||
const state = { | ||
tag: false, | ||
string: null, | ||
}; | ||
const endOfSource = (index) => index + 1 > length; | ||
@@ -223,7 +230,7 @@ const lookahead = (n = 1) => (endOfSource(i + n) ? '' : source[i + n]); | ||
const close = range(i, tag.close.length); | ||
if (open === tag.open.value) { | ||
if (inTag) { | ||
if (open === tag.open.value && state.string == null) { | ||
if (state.tag) { | ||
unclosed(input, output); | ||
} | ||
inTag = true; | ||
state.tag = true; | ||
consumeBuffer(); | ||
@@ -246,3 +253,3 @@ i += tag.open.length - 1; | ||
} | ||
else if (close === tag.close.value) { | ||
else if (close === tag.close.value && state.string == null) { | ||
const token = (0, tokens_1.createToken)('CLOSE_TAG', close, { | ||
@@ -257,6 +264,6 @@ start: { | ||
}); | ||
if (!inTag) { | ||
if (!state.tag) { | ||
unopened(input, token); | ||
} | ||
inTag = false; | ||
state.tag = false; | ||
output.push(...tokenizeInTag({ source: input, input: buf2str(), pos }), token); | ||
@@ -279,6 +286,6 @@ i += tag.close.length - 1; | ||
}); | ||
if (!inTag) { | ||
if (!state.tag) { | ||
unopened(input, token); | ||
} | ||
inTag = false; | ||
state.tag = false; | ||
output.push(...tokenizeInTag({ source: input, input: buf2str(), pos }), token); | ||
@@ -293,2 +300,13 @@ i += tag.close.length; | ||
} | ||
else if (str === '"' || str === "'") { | ||
if (state.tag) { | ||
if (state.string == null) { | ||
state.string = str; | ||
} | ||
else if (state.string === str) { | ||
state.string = null; | ||
} | ||
} | ||
buf.push(str); | ||
} | ||
else { | ||
@@ -304,3 +322,3 @@ buf.push(str); | ||
} | ||
if (inTag) { | ||
if (state.tag) { | ||
unclosed(input, output); | ||
@@ -307,0 +325,0 @@ } |
{ | ||
"name": "@scaffdog/engine", | ||
"version": "1.2.0", | ||
"version": "1.2.1-canary.0", | ||
"description": "A module of scaffdog template engine.", | ||
@@ -32,4 +32,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@scaffdog/error": "1.2.0", | ||
"@scaffdog/types": "1.2.0", | ||
"@scaffdog/error": "1.2.1-canary.0", | ||
"@scaffdog/types": "1.2.1-canary.0", | ||
"change-case": "^4.1.2", | ||
@@ -47,3 +47,3 @@ "dayjs": "^1.10.4", | ||
}, | ||
"gitHead": "be44fc43d7b771c9464b780fc4c8ca18acebfb0c" | ||
"gitHead": "08ea26bd79ab07602c492569df24476052b343bc" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
48340
1343
1
+ Added@scaffdog/error@1.2.1-canary.0(transitive)
+ Added@scaffdog/types@1.2.1-canary.0(transitive)
- Removed@scaffdog/error@1.2.0(transitive)
- Removed@scaffdog/types@1.2.0(transitive)