[ci] npm run format
This commit is contained in:
parent
ad9c3b1d8d
commit
62924b3162
5 changed files with 44 additions and 47 deletions
|
@ -94,7 +94,7 @@ function getAttributes(attrs: Attribute[]): Record<string, string> {
|
|||
|
||||
/** Get value from a TemplateNode Attribute (text attributes only!) */
|
||||
function getTextFromAttribute(attr: any): string {
|
||||
switch(attr.type) {
|
||||
switch (attr.type) {
|
||||
case 'Text': {
|
||||
if (attr.raw !== undefined) {
|
||||
return attr.raw;
|
||||
|
@ -479,7 +479,7 @@ function compileHtml(enterNode: TemplateNode, state: CodegenState, compileOption
|
|||
switch (node.type) {
|
||||
case 'Expression': {
|
||||
let child = '';
|
||||
if(node.children!.length) {
|
||||
if (node.children!.length) {
|
||||
child = compileHtml(node.children![0], state, compileOptions);
|
||||
}
|
||||
let raw = node.codeStart + child + node.codeEnd;
|
||||
|
|
|
@ -65,8 +65,8 @@ export default function (module: Script): Transformer {
|
|||
type: 'Expression',
|
||||
codeStart: '`' + escape(code) + '`',
|
||||
codeEnd: '',
|
||||
children: []
|
||||
}
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import type { BaseNode, Expression } from '../../interfaces';
|
||||
import { Parser } from '../index.js';
|
||||
import parseAstro from '../index.js';
|
||||
|
@ -20,11 +19,11 @@ function peek_nonwhitespace(state: ParseState) {
|
|||
let index = state.index;
|
||||
do {
|
||||
let char = state.source[index];
|
||||
if(!/\s/.test(char)) {
|
||||
if (!/\s/.test(char)) {
|
||||
return char;
|
||||
}
|
||||
index++;
|
||||
} while(index < state.source.length);
|
||||
} while (index < state.source.length);
|
||||
}
|
||||
|
||||
function next_char(state: ParseState) {
|
||||
|
@ -40,38 +39,36 @@ function consume_string(state: ParseState, stringChar: string) {
|
|||
do {
|
||||
const char = next_char(state);
|
||||
|
||||
if(inEscape) {
|
||||
if (inEscape) {
|
||||
inEscape = false;
|
||||
} else if(char === '\\') {
|
||||
} else if (char === '\\') {
|
||||
inEscape = true;
|
||||
} else if(char === stringChar) {
|
||||
} else if (char === stringChar) {
|
||||
break;
|
||||
}
|
||||
} while(in_bounds(state));
|
||||
} while (in_bounds(state));
|
||||
}
|
||||
|
||||
function consume_multiline_comment(state: ParseState) {
|
||||
do {
|
||||
const char = next_char(state);
|
||||
|
||||
if(char === '*' && peek_char(state) === '/') {
|
||||
if (char === '*' && peek_char(state) === '/') {
|
||||
break;
|
||||
}
|
||||
} while(in_bounds(state));
|
||||
} while (in_bounds(state));
|
||||
}
|
||||
|
||||
function consume_line_comment(state: ParseState) {
|
||||
do {
|
||||
const char = next_char(state);
|
||||
if(char === '\n') {
|
||||
if (char === '\n') {
|
||||
break;
|
||||
}
|
||||
} while(in_bounds(state));
|
||||
} while (in_bounds(state));
|
||||
}
|
||||
|
||||
const voidElements = new Set(['area', 'base', 'br', 'col', 'command', 'embed',
|
||||
'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source',
|
||||
'track', 'wbr']);
|
||||
const voidElements = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||
|
||||
function consume_tag(state: ParseState) {
|
||||
const start = state.index - 1;
|
||||
|
@ -85,8 +82,8 @@ function consume_tag(state: ParseState) {
|
|||
do {
|
||||
const char = next_char(state);
|
||||
|
||||
switch(char) {
|
||||
case '\'':
|
||||
switch (char) {
|
||||
case "'":
|
||||
case '"': {
|
||||
consume_string(state, char);
|
||||
break;
|
||||
|
@ -95,7 +92,7 @@ function consume_tag(state: ParseState) {
|
|||
inTag = false;
|
||||
tagName = '';
|
||||
|
||||
if(peek_nonwhitespace(state) === '/') {
|
||||
if (peek_nonwhitespace(state) === '/') {
|
||||
inClose = true;
|
||||
bracketIndex--;
|
||||
} else {
|
||||
|
@ -106,7 +103,7 @@ function consume_tag(state: ParseState) {
|
|||
}
|
||||
case '>': {
|
||||
// An arrow function, probably
|
||||
if(!inStart && !inClose) {
|
||||
if (!inStart && !inClose) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -120,7 +117,7 @@ function consume_tag(state: ParseState) {
|
|||
// If we're in a start tag, we expect to find 2 more brackets
|
||||
!inClose;
|
||||
|
||||
if(addExpectedBrackets) {
|
||||
if (addExpectedBrackets) {
|
||||
bracketIndex += 2;
|
||||
}
|
||||
|
||||
|
@ -135,13 +132,13 @@ function consume_tag(state: ParseState) {
|
|||
break;
|
||||
}
|
||||
case '/': {
|
||||
if(inStart) {
|
||||
if (inStart) {
|
||||
selfClosed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if(!inTag) {
|
||||
if (!inTag) {
|
||||
tagName += char;
|
||||
}
|
||||
break;
|
||||
|
@ -149,18 +146,17 @@ function consume_tag(state: ParseState) {
|
|||
}
|
||||
|
||||
// Unclosed tags
|
||||
if(state.curlyCount <= 0) {
|
||||
if (state.curlyCount <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(bracketIndex === 0) {
|
||||
if (bracketIndex === 0) {
|
||||
break;
|
||||
}
|
||||
} while(in_bounds(state));
|
||||
} while (in_bounds(state));
|
||||
|
||||
const source = state.source.substring(start, state.index);
|
||||
|
||||
|
||||
const ast = parseAstro(source);
|
||||
const fragment = ast.html;
|
||||
|
||||
|
@ -174,21 +170,23 @@ function consume_expression(source: string, start: number): Expression {
|
|||
end: Number.NaN,
|
||||
codeStart: '',
|
||||
codeEnd: '',
|
||||
children: []
|
||||
children: [],
|
||||
};
|
||||
|
||||
let codeEndStart: number = 0;
|
||||
const state: ParseState = {
|
||||
source, start, index: start,
|
||||
source,
|
||||
start,
|
||||
index: start,
|
||||
curlyCount: 1,
|
||||
bracketCount: 0,
|
||||
root: expr
|
||||
root: expr,
|
||||
};
|
||||
|
||||
do {
|
||||
const char = next_char(state);
|
||||
|
||||
switch(char) {
|
||||
|
||||
switch (char) {
|
||||
case '{': {
|
||||
state.curlyCount++;
|
||||
break;
|
||||
|
@ -204,14 +202,14 @@ function consume_expression(source: string, start: number): Expression {
|
|||
codeEndStart = state.index;
|
||||
break;
|
||||
}
|
||||
case '\'':
|
||||
case "'":
|
||||
case '"':
|
||||
case '`': {
|
||||
consume_string(state, char);
|
||||
break;
|
||||
}
|
||||
case '/': {
|
||||
switch(peek_char(state)) {
|
||||
switch (peek_char(state)) {
|
||||
case '/': {
|
||||
consume_line_comment(state);
|
||||
break;
|
||||
|
@ -223,11 +221,11 @@ function consume_expression(source: string, start: number): Expression {
|
|||
}
|
||||
}
|
||||
}
|
||||
} while(in_bounds(state) && state.curlyCount > 0);
|
||||
} while (in_bounds(state) && state.curlyCount > 0);
|
||||
|
||||
expr.end = state.index - 1;
|
||||
|
||||
if(codeEndStart) {
|
||||
if (codeEndStart) {
|
||||
expr.codeEnd = source.substring(codeEndStart, expr.end);
|
||||
} else {
|
||||
expr.codeStart = source.substring(start, expr.end);
|
||||
|
|
|
@ -4,7 +4,6 @@ import type { Node } from 'estree';
|
|||
import { Parser } from '../index.js';
|
||||
import { Script } from '../../interfaces.js';
|
||||
|
||||
|
||||
const script_closing_tag = '</script>';
|
||||
|
||||
function get_context(parser: Parser, attributes: any[], start: number): 'runtime' | 'setup' {
|
||||
|
|
|
@ -11,10 +11,10 @@ Expressions('Can load page', async ({ runtime }) => {
|
|||
const result = await runtime.load('/');
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
for(let col of ['red', 'yellow', 'blue']) {
|
||||
for (let col of ['red', 'yellow', 'blue']) {
|
||||
assert.equal($('#' + col).length, 1);
|
||||
}
|
||||
});
|
||||
|
@ -23,10 +23,10 @@ Expressions('Ignores characters inside of strings', async ({ runtime }) => {
|
|||
const result = await runtime.load('/strings');
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
for(let col of ['red', 'yellow', 'blue']) {
|
||||
for (let col of ['red', 'yellow', 'blue']) {
|
||||
assert.equal($('#' + col).length, 1);
|
||||
}
|
||||
});
|
||||
|
@ -34,10 +34,10 @@ Expressions('Ignores characters inside of strings', async ({ runtime }) => {
|
|||
Expressions('Ignores characters inside of line comments', async ({ runtime }) => {
|
||||
const result = await runtime.load('/line-comments');
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
for(let col of ['red', 'yellow', 'blue']) {
|
||||
for (let col of ['red', 'yellow', 'blue']) {
|
||||
assert.equal($('#' + col).length, 1);
|
||||
}
|
||||
});
|
||||
|
@ -45,10 +45,10 @@ Expressions('Ignores characters inside of line comments', async ({ runtime }) =>
|
|||
Expressions('Ignores characters inside of multiline comments', async ({ runtime }) => {
|
||||
const result = await runtime.load('/multiline-comments');
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
for(let col of ['red', 'yellow', 'blue']) {
|
||||
for (let col of ['red', 'yellow', 'blue']) {
|
||||
assert.equal($('#' + col).length, 1);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue