-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import FileAttachment #325
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ import {findAwaits} from "./javascript/awaits.js"; | |
import {resolveDatabases} from "./javascript/databases.js"; | ||
import {findDeclarations} from "./javascript/declarations.js"; | ||
import {findFeatures} from "./javascript/features.js"; | ||
import {rewriteFetches} from "./javascript/fetches.js"; | ||
import {defaultGlobals} from "./javascript/globals.js"; | ||
import {findExports, findImportDeclarations, findImports} from "./javascript/imports.js"; | ||
import {createImportResolver, rewriteImports} from "./javascript/imports.js"; | ||
import {findReferences} from "./javascript/references.js"; | ||
|
@@ -20,9 +18,11 @@ export interface DatabaseReference { | |
} | ||
|
||
export interface FileReference { | ||
/** The relative path from the source root to the file. */ | ||
name: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the name is still the relative path from the page to the file?
and in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can double check but there is a difference between Feature.name, FileAttachment.name in generated code, and FileReference.name. It’s all a bit hard to keep straight. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right! 👍 Sorry, I was confused. I’ve updated the comment. |
||
/** The MIME type, if known; derived from the file extension. */ | ||
mimeType: string | null; | ||
/** The relative path from the document to the file in _file */ | ||
/** The relative path from the page to the file in _file. */ | ||
path: string; | ||
} | ||
|
||
|
@@ -93,7 +93,6 @@ export function transpileJavaScript(input: string, options: ParseOptions): Pendi | |
output.insertRight(input.length, "\n))"); | ||
} | ||
await rewriteImports(output, node, sourcePath, createImportResolver(root, "_import")); | ||
rewriteFetches(output, node, sourcePath); | ||
const result = `${node.async ? "async " : ""}(${inputs}) => { | ||
${String(output)}${node.declarations?.length ? `\nreturn {${node.declarations.map(({name}) => name)}};` : ""} | ||
}`; | ||
|
@@ -143,7 +142,7 @@ export interface JavaScriptNode { | |
} | ||
|
||
function parseJavaScript(input: string, options: ParseOptions): JavaScriptNode { | ||
const {globals = defaultGlobals, inline = false, root, sourcePath} = options; | ||
const {inline = false, root, sourcePath} = options; | ||
// First attempt to parse as an expression; if this fails, parse as a program. | ||
let expression = maybeParseExpression(input, parseOptions); | ||
if (expression?.type === "ClassExpression" && expression.id) expression = null; // treat named class as program | ||
|
@@ -152,16 +151,16 @@ function parseJavaScript(input: string, options: ParseOptions): JavaScriptNode { | |
const body = expression ?? Parser.parse(input, parseOptions); | ||
const exports = findExports(body); | ||
if (exports.length) throw syntaxError("Unexpected token 'export'", exports[0], input); // disallow exports | ||
const references = findReferences(body, globals); | ||
findAssignments(body, references, globals, input); | ||
const declarations = expression ? null : findDeclarations(body as Program, globals, input); | ||
const {imports, fetches} = findImports(body, root, sourcePath); | ||
const features = findFeatures(body, root, sourcePath, references, input); | ||
const references = findReferences(body); | ||
findAssignments(body, references, input); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const declarations = expression ? null : findDeclarations(body as Program, input); | ||
const {imports, features: importedFeatures} = findImports(body, root, sourcePath); | ||
const features = findFeatures(body, sourcePath, references, input); | ||
return { | ||
body, | ||
declarations, | ||
references, | ||
features: [...features, ...fetches], | ||
features: [...features, ...importedFeatures], | ||
imports, | ||
expression: !!expression, | ||
async: findAwaits(body).length > 0 | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going to continue reviewing tomorrow