parse() — svelte Function Reference
Architecture documentation for the parse() function in acorn.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD f47134ed_b840_afa5_bf63_d93768eb2045["parse()"] 2627a38d_1d02_8fc1_b764_b2aaf06f372b["acorn.js"] f47134ed_b840_afa5_bf63_d93768eb2045 -->|defined in| 2627a38d_1d02_8fc1_b764_b2aaf06f372b 3f7147bd_f765_d166_38e7_10f71b9fd062["read_script()"] 3f7147bd_f765_d166_38e7_10f71b9fd062 -->|calls| f47134ed_b840_afa5_bf63_d93768eb2045 05334dc2_42b5_e2cb_fe55_aa3f6a2de9df["analyze_module()"] 05334dc2_42b5_e2cb_fe55_aa3f6a2de9df -->|calls| f47134ed_b840_afa5_bf63_d93768eb2045 9bfeaa6b_e84a_de23_08c7_df130f4cacf9["get_comment_handlers()"] f47134ed_b840_afa5_bf63_d93768eb2045 -->|calls| 9bfeaa6b_e84a_de23_08c7_df130f4cacf9 style f47134ed_b840_afa5_bf63_d93768eb2045 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/1-parse/acorn.js lines 22–66
export function parse(source, comments, typescript, is_script) {
const parser = typescript ? ParserWithTS : acorn.Parser;
const { onComment, add_comments } = get_comment_handlers(
source,
/** @type {CommentWithLocation[]} */ (comments)
);
// @ts-ignore
const parse_statement = parser.prototype.parseStatement;
// If we're dealing with a <script> then it might contain an export
// for something that doesn't exist directly inside but is inside the
// component instead, so we need to ensure that Acorn doesn't throw
// an error in these cases
if (is_script) {
// @ts-ignore
parser.prototype.parseStatement = function (...args) {
const v = parse_statement.call(this, ...args);
// @ts-ignore
this.undefinedExports = {};
return v;
};
}
let ast;
try {
ast = parser.parse(source, {
onComment,
sourceType: 'module',
ecmaVersion: 16,
locations: true
});
} finally {
if (is_script) {
// @ts-ignore
parser.prototype.parseStatement = parse_statement;
}
}
add_comments(ast);
return /** @type {Program} */ (ast);
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/1-parse/acorn.js.
Where is parse() defined?
parse() is defined in packages/svelte/src/compiler/phases/1-parse/acorn.js at line 22.
What does parse() call?
parse() calls 1 function(s): get_comment_handlers.
What calls parse()?
parse() is called by 2 function(s): analyze_module, read_script.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free