feat: support WRN imports and dynamic public shell
This commit is contained in:
@@ -382,6 +382,24 @@ function unescapeSeoValue(value) {
|
||||
}
|
||||
function parse(source) {
|
||||
const lx = new Lexer(source);
|
||||
const imports = [];
|
||||
const importPattern = /import\s+(?:type\s+)?(?:[\s\S]*?\s+from\s+)?["'][^"'\r\n]+["']\s*;?/y;
|
||||
while (true) {
|
||||
while (/\s/u.test(source[lx.pos] ?? ""))
|
||||
lx.pos++;
|
||||
if (source.startsWith("//", lx.pos)) {
|
||||
while (lx.pos < source.length && source[lx.pos] !== `
|
||||
`)
|
||||
lx.pos++;
|
||||
continue;
|
||||
}
|
||||
importPattern.lastIndex = lx.pos;
|
||||
const statement = importPattern.exec(source);
|
||||
if (!statement)
|
||||
break;
|
||||
imports.push(statement[0].trim());
|
||||
lx.pos = importPattern.lastIndex;
|
||||
}
|
||||
const expect = (type) => {
|
||||
const t = lx.next();
|
||||
if (t.type !== type) {
|
||||
@@ -627,6 +645,7 @@ function parse(source) {
|
||||
}
|
||||
return {
|
||||
type: "page",
|
||||
imports,
|
||||
kind,
|
||||
name,
|
||||
layout,
|
||||
@@ -1304,6 +1323,9 @@ function generate(ast) {
|
||||
return generateComponent(ast);
|
||||
}
|
||||
const out = [];
|
||||
if (ast.imports.length > 0)
|
||||
out.push(ast.imports.join(`
|
||||
`));
|
||||
const ssrBindings = [];
|
||||
const csrBindings = [];
|
||||
const helpers = ast.functions.map((body2) => body2.trim()).filter(Boolean).join(`
|
||||
@@ -1722,6 +1744,9 @@ function renderComponentNode(node, ctx) {
|
||||
}
|
||||
function generateComponent(ast) {
|
||||
const out = [];
|
||||
if (ast.imports.length > 0)
|
||||
out.push(ast.imports.join(`
|
||||
`));
|
||||
const hasServerEach = viewHasServerEach(ast.view);
|
||||
if (hasServerEach) {
|
||||
out.push(`import { Buffer } from "node:buffer";`);
|
||||
@@ -2192,6 +2217,8 @@ function generateNative(ast) {
|
||||
import React, { useState } from "react";
|
||||
import { ActivityIndicator, FlatList, Image, Pressable, SafeAreaView, ScrollView, StyleSheet, Text, TextInput, View } from "react-native";
|
||||
import { useRouter } from "expo-router";
|
||||
${ast.imports.join(`
|
||||
`)}
|
||||
|
||||
${typeSource}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user