summaryrefslogtreecommitdiff
path: root/packages/astro-parser/src/parse
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-07-21 10:22:39 -0400
committerGravatar GitHub <noreply@github.com> 2021-07-21 10:22:39 -0400
commitb85e68a7131b5c582c50f1614a07a5b47cd65850 (patch)
tree0deed51c9d2e138801cd9165d6ccb3ec00bb498f /packages/astro-parser/src/parse
parentb7e579a9cbdef761c704e92cf3d2dab95fe9eb8d (diff)
downloadastro-b85e68a7131b5c582c50f1614a07a5b47cd65850.tar.gz
astro-b85e68a7131b5c582c50f1614a07a5b47cd65850.tar.zst
astro-b85e68a7131b5c582c50f1614a07a5b47cd65850.zip
Handle custom elements in nested JSX (#792)
* Handle custom elements in nested JSX * Adds a changeset
Diffstat (limited to 'packages/astro-parser/src/parse')
-rw-r--r--packages/astro-parser/src/parse/index.ts2
-rw-r--r--packages/astro-parser/src/parse/read/expression.ts11
2 files changed, 8 insertions, 5 deletions
diff --git a/packages/astro-parser/src/parse/index.ts b/packages/astro-parser/src/parse/index.ts
index 9b9f87073..ef33bfaca 100644
--- a/packages/astro-parser/src/parse/index.ts
+++ b/packages/astro-parser/src/parse/index.ts
@@ -29,7 +29,7 @@ export class Parser {
js: Script[] = [];
meta_tags = {};
last_auto_closed_tag?: LastAutoClosedTag;
- feature_flags: 0;
+ feature_flags: number = 0;
constructor(template: string, options: ParserOptions) {
if (typeof template !== 'string') {
diff --git a/packages/astro-parser/src/parse/read/expression.ts b/packages/astro-parser/src/parse/read/expression.ts
index 98d94e26a..b4647ab06 100644
--- a/packages/astro-parser/src/parse/read/expression.ts
+++ b/packages/astro-parser/src/parse/read/expression.ts
@@ -9,6 +9,7 @@ interface ParseState {
curlyCount: number;
bracketCount: number;
root: Expression;
+ parser: Parser;
}
function peek_char(state: ParseState) {
@@ -159,12 +160,13 @@ function consume_tag(state: ParseState) {
const source = state.source.substring(start, state.index);
const ast = parseAstro(source);
+ state.parser.feature_flags |= ast.meta.features;
const fragment = ast.html;
return fragment;
}
-function consume_expression(source: string, start: number): Expression {
+function consume_expression(parser: Parser, source: string, start: number): Expression {
const expr: Expression = {
type: 'Expression',
start,
@@ -182,6 +184,7 @@ function consume_expression(source: string, start: number): Expression {
curlyCount: 1,
bracketCount: 0,
root: expr,
+ parser,
};
do {
@@ -234,15 +237,15 @@ function consume_expression(source: string, start: number): Expression {
return expr;
}
-export const parse_expression_at = (source: string, index: number): Expression => {
- const expression = consume_expression(source, index);
+export const parse_expression_at = (parser: Parser, source: string, index: number): Expression => {
+ const expression = consume_expression(parser, source, index);
return expression;
};
export default function read_expression(parser: Parser) {
try {
- const expression = parse_expression_at(parser.template, parser.index);
+ const expression = parse_expression_at(parser, parser.template, parser.index);
parser.index = expression.end;
return expression;
} catch (err) {