Merge pull request #2534 from clebert/public-parse

Expose `parse` to the public
pull/2675/head
Rich Harris 6 years ago committed by GitHub
commit d3d5fa9360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -153,6 +153,30 @@ compiled: {
-->
### `svelte.parse`
```js
ast: object = svelte.parse(
source: string,
options?: {
filename?: string,
customElement?: boolean
}
)
```
---
The `parse` function parses a component, returning only its abstract syntax tree. Unlike compiling with the `generate: false` option, this will not perform any validation or other analysis of the component beyond parsing it.
```js
const svelte = require('svelte/compiler');
const ast = svelte.parse(source, { filename: 'App.svelte' });
```
### `svelte.preprocess`
```js

@ -1,4 +1,5 @@
export { default as compile } from './compile/index';
export { default as parse } from './parse/index';
export { default as preprocess } from './preprocess/index';
export const VERSION = '__VERSION__';

@ -61,6 +61,11 @@ export interface CompileOptions {
preserveWhitespace?: boolean;
}
export interface ParserOptions {
filename?: string;
customElement?: boolean;
}
export interface Visitor {
enter: (node: Node) => void;
leave?: (node: Node) => void;

@ -3,14 +3,9 @@ import fragment from './state/fragment';
import { whitespace } from '../utils/patterns';
import { reserved } from '../utils/names';
import full_char_code_at from '../utils/full_char_code_at';
import { Node, Ast } from '../interfaces';
import { Node, Ast, ParserOptions } from '../interfaces';
import error from '../utils/error';
interface ParserOptions {
filename?: string;
customElement?: boolean;
}
type ParserState = (parser: Parser) => (ParserState | void);
export class Parser {

Loading…
Cancel
Save