svelte-eslint-parser
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -28,3 +28,4 @@ import type ESTree from "estree"; | ||
} | ||
export declare type SvelteNode = SvelteProgram | SvelteScriptElement | SvelteStyleElement | SvelteElement | SvelteName | SvelteText | SvelteMustacheTag | SvelteDebugTag | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteAttribute | SvelteSpreadAttribute | SvelteDirective | SvelteHTMLComment | SvelteReactiveStatement; | ||
export declare type SvelteNode = SvelteProgram | SvelteScriptElement | SvelteStyleElement | SvelteElement | SvelteName | SvelteText | SvelteMustacheTag | SvelteDebugTag | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective | SvelteHTMLComment | SvelteReactiveStatement; | ||
/** Node of Svelte program root */ | ||
export interface SvelteProgram extends BaseNode { | ||
@@ -38,17 +39,22 @@ type: "Program"; | ||
} | ||
/** Node of elements like HTML element. */ | ||
export declare type SvelteElement = SvelteHTMLElement | SvelteComponentElement | SvelteSpecialElement; | ||
declare type BaseSvelteElement = BaseNode; | ||
/** Node of `<script>` element. */ | ||
export interface SvelteScriptElement extends BaseSvelteElement { | ||
type: "SvelteScriptElement"; | ||
name: SvelteName; | ||
attributes: (SvelteAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
attributes: (SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
body: ESTree.Program["body"]; | ||
parent: SvelteProgram; | ||
} | ||
/** Node of `<style>` element. */ | ||
export interface SvelteStyleElement extends BaseSvelteElement { | ||
type: "SvelteStyleElement"; | ||
name: SvelteName; | ||
attributes: (SvelteAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
attributes: (SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
children: [SvelteText]; | ||
parent: SvelteProgram; | ||
} | ||
/** Node of HTML element. */ | ||
export interface SvelteHTMLElement extends BaseSvelteElement { | ||
@@ -58,6 +64,7 @@ type: "SvelteElement"; | ||
name: SvelteName; | ||
attributes: (SvelteAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
attributes: (SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
children: Child[]; | ||
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock; | ||
} | ||
/** Node of Svelte component element. */ | ||
export interface SvelteComponentElement extends BaseSvelteElement { | ||
@@ -67,6 +74,7 @@ type: "SvelteElement"; | ||
name: ESTree.Identifier; | ||
attributes: (SvelteAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
attributes: (SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective)[]; | ||
children: Child[]; | ||
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock; | ||
} | ||
/** Node of Svelte special component element. e.g. `<svelte:window>` */ | ||
export interface SvelteSpecialElement extends BaseSvelteElement { | ||
@@ -76,13 +84,14 @@ type: "SvelteElement"; | ||
name: SvelteName; | ||
attributes: (SvelteAttribute | SvelteSpreadAttribute | SvelteDirective | SvelteSpecialDirective)[]; | ||
attributes: (SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective | SvelteSpecialDirective)[]; | ||
children: Child[]; | ||
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock; | ||
} | ||
export declare type SvelteElement = SvelteHTMLElement | SvelteComponentElement | SvelteSpecialElement; | ||
/** Node of names. It is used for element names other than components and normal attribute names. */ | ||
export interface SvelteName extends BaseNode { | ||
type: "SvelteName"; | ||
name: string; | ||
parent: SvelteElement | SvelteScriptElement | SvelteStyleElement; | ||
parent: SvelteElement | SvelteScriptElement | SvelteStyleElement | SvelteAttribute; | ||
} | ||
declare type Child = SvelteElement | SvelteText | SvelteMustacheTag | SvelteDebugTag | SvelteIfBlock | SvelteEachBlock | SvelteAwaitBlock | SvelteKeyBlock | SvelteHTMLComment; | ||
/** Node of text line HTML text. */ | ||
export interface SvelteText extends BaseNode { | ||
@@ -96,2 +105,3 @@ type: "SvelteText"; | ||
} | ||
/** Node of mustache tag. e.g. `{...}`, `{@html ...}` */ | ||
export interface SvelteMustacheTag extends BaseSvelteMustacheTag { | ||
@@ -102,2 +112,3 @@ type: "SvelteMustacheTag"; | ||
} | ||
/** Node of debug mustache tag. e.g. `{@debug}` */ | ||
export interface SvelteDebugTag extends BaseSvelteMustacheTag { | ||
@@ -107,2 +118,3 @@ type: "SvelteDebugTag"; | ||
} | ||
/** Node of if block. e.g. `{#if}` */ | ||
export interface SvelteIfBlock extends BaseNode { | ||
@@ -116,2 +128,3 @@ type: "SvelteIfBlock"; | ||
} | ||
/** Node of else block. e.g. `{:else}` */ | ||
export interface SvelteElseBlock extends BaseNode { | ||
@@ -122,2 +135,3 @@ type: "SvelteElseBlock"; | ||
} | ||
/** Node of each block. e.g. `{#each}` */ | ||
export interface SvelteEachBlock extends BaseNode { | ||
@@ -133,2 +147,3 @@ type: "SvelteEachBlock"; | ||
} | ||
/** Node of await block. e.g. `{#await}` */ | ||
export interface SvelteAwaitBlock extends BaseNode { | ||
@@ -142,2 +157,3 @@ type: "SvelteAwaitBlock"; | ||
} | ||
/** Node of await pending block. e.g. `{#await expr} ... {:then}` */ | ||
export interface SvelteAwaitPendingBlock extends BaseNode { | ||
@@ -148,2 +164,3 @@ type: "SvelteAwaitPendingBlock"; | ||
} | ||
/** Node of await then block. e.g. `{:then}` */ | ||
export interface SvelteAwaitThenBlock extends BaseNode { | ||
@@ -155,2 +172,3 @@ type: "SvelteAwaitThenBlock"; | ||
} | ||
/** Node of await catch block. e.g. `{:catch}` */ | ||
export interface SvelteAwaitCatchBlock extends BaseNode { | ||
@@ -162,2 +180,3 @@ type: "SvelteAwaitCatchBlock"; | ||
} | ||
/** Node of key block. e.g. `{#key}` */ | ||
export interface SvelteKeyBlock extends BaseNode { | ||
@@ -169,2 +188,3 @@ type: "SvelteKeyBlock"; | ||
} | ||
/** Node of HTML comment. */ | ||
export interface SvelteHTMLComment extends BaseNode { | ||
@@ -175,6 +195,6 @@ type: "SvelteHTMLComment"; | ||
} | ||
export interface SvelteAttributeNonShorthand extends BaseNode { | ||
/** Node of HTML comment. */ | ||
export interface SvelteAttribute extends BaseNode { | ||
type: "SvelteAttribute"; | ||
key: ESTree.Identifier; | ||
shorthand: false; | ||
key: SvelteName; | ||
boolean: boolean; | ||
@@ -186,11 +206,10 @@ value: (SvelteText | (SvelteMustacheTag & { | ||
} | ||
export interface SvelteAttributeShorthand extends BaseNode { | ||
type: "SvelteAttribute"; | ||
/** Node of shorthand attribute. e.g. `<img {src}>` */ | ||
export interface SvelteShorthandAttribute extends BaseNode { | ||
type: "SvelteShorthandAttribute"; | ||
key: ESTree.Identifier; | ||
shorthand: true; | ||
boolean: boolean; | ||
value: [ESTree.Identifier]; | ||
value: ESTree.Identifier; | ||
parent: SvelteElement | SvelteScriptElement | SvelteStyleElement; | ||
} | ||
export declare type SvelteAttribute = SvelteAttributeNonShorthand | SvelteAttributeShorthand; | ||
/** Node of spread attribute. e.g. `<Info {...pkg}/>` */ | ||
export interface SvelteSpreadAttribute extends BaseNode { | ||
@@ -201,2 +220,4 @@ type: "SvelteSpreadAttribute"; | ||
} | ||
/** Node of directive. e.g. `<input bind:value />` */ | ||
export declare type SvelteDirective = SvelteActionDirective | SvelteAnimationDirective | SvelteBindingDirective | SvelteClassDirective | SvelteEventHandlerDirective | SvelteLetDirective | SvelteRefDirective | SvelteTransitionDirective; | ||
interface BaseSvelteDirective extends BaseNode { | ||
@@ -248,3 +269,3 @@ type: "SvelteDirective"; | ||
} | ||
export declare type SvelteDirective = SvelteActionDirective | SvelteAnimationDirective | SvelteBindingDirective | SvelteClassDirective | SvelteEventHandlerDirective | SvelteLetDirective | SvelteRefDirective | SvelteTransitionDirective; | ||
/** Node of `$` statement. */ | ||
export interface SvelteReactiveStatement extends BaseNode { | ||
@@ -251,0 +272,0 @@ type: "SvelteReactiveStatement"; |
@@ -1,5 +0,5 @@ | ||
import type { SvelteAttribute, SvelteDirective, SvelteElement, SvelteScriptElement, SvelteSpreadAttribute, SvelteStyleElement } from "../../ast"; | ||
import type { SvelteAttribute, SvelteShorthandAttribute, SvelteDirective, SvelteElement, SvelteScriptElement, SvelteSpreadAttribute, SvelteStyleElement } from "../../ast"; | ||
import type { Context } from "../../context"; | ||
import type * as SvAST from "../svelte-ast-types"; | ||
/** Convert for Attributes */ | ||
export declare function convertAttributes(attributes: SvAST.AttributeOrDirective[], parent: SvelteElement | SvelteScriptElement | SvelteStyleElement, ctx: Context): IterableIterator<SvelteAttribute | SvelteSpreadAttribute | SvelteDirective>; | ||
export declare function convertAttributes(attributes: SvAST.AttributeOrDirective[], parent: SvelteElement | SvelteScriptElement | SvelteStyleElement, ctx: Context): IterableIterator<SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective>; |
@@ -57,6 +57,6 @@ "use strict"; | ||
function convertAttribute(node, parent, ctx) { | ||
const attribute = Object.assign({ type: "SvelteAttribute", shorthand: false, boolean: false, key: null, value: [], parent }, ctx.getConvertLocation(node)); | ||
const attribute = Object.assign({ type: "SvelteAttribute", boolean: false, key: null, value: [], parent }, ctx.getConvertLocation(node)); | ||
const keyStart = ctx.code.indexOf(node.name, node.start); | ||
const keyRange = { start: keyStart, end: keyStart + node.name.length }; | ||
attribute.key = Object.assign({ type: "Identifier", name: node.name }, ctx.getConvertLocation(keyRange)); | ||
attribute.key = Object.assign({ type: "SvelteName", name: node.name, parent: attribute }, ctx.getConvertLocation(keyRange)); | ||
ctx.addToken("HTMLIdentifier", keyRange); | ||
@@ -70,4 +70,13 @@ if (node.value === true) { | ||
if (v.type === "AttributeShorthand") { | ||
const sAttr = Object.assign(Object.assign({}, attribute), { shorthand: true, value: [attribute.key] }); | ||
es_1.analyzeExpressionScope(attribute.key, ctx); | ||
const key = Object.assign(Object.assign({}, attribute.key), { type: "Identifier" }); | ||
const sAttr = { | ||
type: "SvelteShorthandAttribute", | ||
key, | ||
value: key, | ||
parent, | ||
loc: attribute.loc, | ||
range: attribute.range, | ||
}; | ||
key.parent = sAttr; | ||
es_1.analyzeExpressionScope(sAttr.key, ctx); | ||
return sAttr; | ||
@@ -74,0 +83,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
const sort_1 = require("./sort"); | ||
const __1 = require(".."); | ||
/** | ||
@@ -12,12 +13,22 @@ * Parse for template | ||
function parseTemplate(code, ctx, parserOptions = {}) { | ||
const svelteAst = compiler_1.parse(code, { | ||
filename: parserOptions.filePath, | ||
}); | ||
const ast = index_1.convertSvelteRoot(svelteAst, ctx); | ||
sort_1.sort(ast.body); | ||
return { | ||
ast, | ||
svelteAst, | ||
}; | ||
try { | ||
const svelteAst = compiler_1.parse(code, { | ||
filename: parserOptions.filePath, | ||
}); | ||
const ast = index_1.convertSvelteRoot(svelteAst, ctx); | ||
sort_1.sort(ast.body); | ||
return { | ||
ast, | ||
svelteAst, | ||
}; | ||
} | ||
catch (e) { | ||
if (typeof e.pos === "number") { | ||
const err = new __1.ParseError(e.message, e.pos, ctx); | ||
err.svelteCompilerError = e; | ||
throw err; | ||
} | ||
throw e; | ||
} | ||
} | ||
exports.parseTemplate = parseTemplate; |
@@ -29,2 +29,3 @@ "use strict"; | ||
SvelteAttribute: ["key", "value"], | ||
SvelteShorthandAttribute: ["key", "value"], | ||
SvelteSpreadAttribute: ["expression"], | ||
@@ -31,0 +32,0 @@ SvelteDirective: ["expression"], |
{ | ||
"name": "svelte-eslint-parser", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Svelte parser for ESLint", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122337
2953