Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

svelte-eslint-parser

Package Overview
Dependencies
Maintainers
4
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-eslint-parser - npm Package Compare versions

Comparing version 0.34.0-next.11 to 0.34.0-next.12

4

lib/context/index.d.ts

@@ -20,6 +20,6 @@ /// <reference types="svelte" />

render: string;
generics: string;
rootScope: string;
};
getCurrentVirtualCodeLength(): number;
addLet(letCode: string, kind: "generics" | "render"): {
addLet(letCode: string, kind: "generics" | "snippet" | "render"): {
start: number;

@@ -26,0 +26,0 @@ end: number;

@@ -26,2 +26,3 @@ "use strict";

this._appendScriptLets.render +
this._appendScriptLets.snippet +
this._appendScriptLets.generics);

@@ -31,3 +32,3 @@ }

if (this._appendScriptLets == null) {
return { script: this.raw, render: "", generics: "" };
return { script: this.raw, render: "", rootScope: "" };
}

@@ -37,3 +38,3 @@ return {

render: this._appendScriptLets.beforeSpaces + this._appendScriptLets.render,
generics: this._appendScriptLets.generics,
rootScope: this._appendScriptLets.snippet + this._appendScriptLets.generics,
};

@@ -49,2 +50,3 @@ }

this._appendScriptLets.render.length +
this._appendScriptLets.snippet.length +
this._appendScriptLets.generics.length);

@@ -61,2 +63,3 @@ }

render: "",
snippet: "",
generics: "",

@@ -63,0 +66,0 @@ };

@@ -50,2 +50,3 @@ import type { ScopeManager, Scope } from "eslint-scope";

private readonly unique;
private currentScriptScopeKind;
constructor(ctx: Context);

@@ -62,3 +63,3 @@ addExpression<E extends ESTree.Expression>(expression: E | SvelteName, parent: SvelteNode, typing?: string | null, ...callbacks: ScriptLetCallback<E>[]): ScriptLetCallback<E>[];

} | null, eachBlock: SvelteEachBlock, callback: (expr: ESTree.Expression, ctx: ESTree.Pattern, index: ESTree.Identifier | null) => void): void;
nestSnippetBlock(id: ESTree.Identifier, closeParentIndex: number, snippetBlock: SvelteSnippetBlock, callback: (id: ESTree.Identifier, params: ESTree.Pattern[]) => void): void;
nestSnippetBlock(id: ESTree.Identifier, closeParentIndex: number, snippetBlock: SvelteSnippetBlock, kind: "snippet" | "render", callback: (id: ESTree.Identifier, params: ESTree.Pattern[]) => void): void;
nestBlock(block: SvelteNode, params?: ScriptLetBlockParam[] | ((helper: TypeGenHelper | null) => {

@@ -65,0 +66,0 @@ param: ScriptLetBlockParam;

@@ -39,2 +39,3 @@ "use strict";

this.unique = new unique_1.UniqueIdGenerator();
this.currentScriptScopeKind = "render";
this.script = ctx.sourceCode.scripts;

@@ -50,3 +51,3 @@ this.ctx = ctx;

const isTS = typing && this.ctx.isTypeScript();
this.appendScript(`(${part})${isTS ? `as (${typing})` : ""};`, range[0] - 1, "render", (st, tokens, comments, result) => {
this.appendScript(`(${part})${isTS ? `as (${typing})` : ""};`, range[0] - 1, this.currentScriptScopeKind, (st, tokens, comments, result) => {
const exprSt = st;

@@ -85,3 +86,3 @@ const tsAs = isTS

const part = this.ctx.code.slice(...range);
this.appendScript(`({${part}});`, range[0] - 2, "render", (st, tokens, _comments, result) => {
this.appendScript(`({${part}});`, range[0] - 2, this.currentScriptScopeKind, (st, tokens, _comments, result) => {
const exprSt = st;

@@ -111,3 +112,3 @@ const objectExpression = exprSt.expression;

const part = this.ctx.code.slice(...range);
this.appendScript(`const ${part};`, range[0] - 6, "render", (st, tokens, _comments, result) => {
this.appendScript(`const ${part};`, range[0] - 6, this.currentScriptScopeKind, (st, tokens, _comments, result) => {
const decl = st;

@@ -206,3 +207,3 @@ const node = decl.declarations[0];

const part = this.ctx.code.slice(...range);
const restore = this.appendScript(`if(${part}){`, range[0] - 3, "render", (st, tokens, _comments, result) => {
const restore = this.appendScript(`if(${part}){`, range[0] - 3, this.currentScriptScopeKind, (st, tokens, _comments, result) => {
const ifSt = st;

@@ -225,3 +226,3 @@ const node = ifSt.test;

});
this.pushScope(restore, "}");
this.pushScope(restore, "}", this.currentScriptScopeKind);
}

@@ -243,3 +244,3 @@ nestEachBlock(expression, context, indexRange, eachBlock, callback) {

source += ")=>{";
const restore = this.appendScript(source, exprRange[0] - exprOffset, "render", (st, tokens, comments, result) => {
const restore = this.appendScript(source, exprRange[0] - exprOffset, this.currentScriptScopeKind, (st, tokens, comments, result) => {
var _a;

@@ -311,8 +312,8 @@ const expSt = st;

});
this.pushScope(restore, "});");
this.pushScope(restore, "});", this.currentScriptScopeKind);
}
nestSnippetBlock(id, closeParentIndex, snippetBlock, callback) {
nestSnippetBlock(id, closeParentIndex, snippetBlock, kind, callback) {
const idRange = getNodeRange(id);
const part = this.ctx.code.slice(idRange[0], closeParentIndex + 1);
const restore = this.appendScript(`function ${part}{`, idRange[0] - 9, "render", (st, tokens, _comments, result) => {
const restore = this.appendScript(`function ${part}{`, idRange[0] - 9, kind, (st, tokens, _comments, result) => {
const fnDecl = st;

@@ -337,3 +338,3 @@ const idNode = fnDecl.id;

});
this.pushScope(restore, "}");
this.pushScope(restore, "}", kind);
}

@@ -350,3 +351,3 @@ nestBlock(block, params) {

for (const preparationScript of generatedTypes.preparationScript) {
this.appendScriptWithoutOffset(preparationScript, "render", (node, tokens, comments, result) => {
this.appendScriptWithoutOffset(preparationScript, this.currentScriptScopeKind, (node, tokens, comments, result) => {
tokens.length = 0;

@@ -368,3 +369,3 @@ comments.length = 0;

if (!resolvedParams || resolvedParams.length === 0) {
const restore = this.appendScript(`{`, block.range[0], "render", (st, tokens, _comments, result) => {
const restore = this.appendScript(`{`, block.range[0], this.currentScriptScopeKind, (st, tokens, _comments, result) => {
const blockSt = st;

@@ -378,3 +379,3 @@ // Process for scope

});
this.pushScope(restore, "}");
this.pushScope(restore, "}", this.currentScriptScopeKind);
}

@@ -410,3 +411,3 @@ else {

}
const restore = this.appendScript(`(${source})=>{`, maps[0].range[0] - 1, "render", (st, tokens, comments, result) => {
const restore = this.appendScript(`(${source})=>{`, maps[0].range[0] - 1, this.currentScriptScopeKind, (st, tokens, comments, result) => {
const exprSt = st;

@@ -456,3 +457,3 @@ const fn = exprSt.expression;

});
this.pushScope(restore, "};");
this.pushScope(restore, "};", this.currentScriptScopeKind);
}

@@ -483,5 +484,8 @@ }

}
pushScope(restoreCallback, closeToken) {
pushScope(restoreCallback, closeToken, kind) {
const upper = this.currentScriptScopeKind;
this.currentScriptScopeKind = kind;
this.closeScopeCallbacks.push(() => {
this.script.addLet(closeToken, "render");
this.script.addLet(closeToken, kind);
this.currentScriptScopeKind = upper;
restoreCallback.end = this.script.getCurrentVirtualCodeLength();

@@ -516,3 +520,15 @@ });

postprocessList.push(() => {
var _a, _b;
const beforeBlock = scope.block;
scope.block = node;
for (const variable of [
...scope.variables,
...((_b = (_a = scope.upper) === null || _a === void 0 ? void 0 : _a.variables) !== null && _b !== void 0 ? _b : []),
]) {
for (const def of variable.defs) {
if (def.node === beforeBlock) {
def.node = node;
}
}
}
});

@@ -519,0 +535,0 @@ const scopes = nodeToScope.get(node);

export declare const name: "svelte-eslint-parser";
export declare const version: "0.34.0-next.11";
export declare const version: "0.34.0-next.12";

@@ -8,2 +8,2 @@ "use strict";

exports.name = "svelte-eslint-parser";
exports.version = "0.34.0-next.11";
exports.version = "0.34.0-next.12";

@@ -176,12 +176,13 @@ "use strict";

const scope = (0, scope_1.getScopeFromNode)(scopeManager, snippet.id);
const variable = scope.upper
? scope.upper.set.get(snippet.id.name)
: null;
if (variable) {
// Add the virtual reference for reading.
const reference = addVirtualReference(snippet.id, variable, scope, {
read: true,
});
reference.svelteSnippetReference = true;
}
const upperScope = scope.upper;
if (!upperScope)
continue;
const variable = upperScope.set.get(snippet.id.name);
if (!variable)
continue;
// Add the virtual reference for reading.
const reference = addVirtualReference(snippet.id, variable, upperScope, {
read: true,
});
reference.svelteSnippetReference = true;
}

@@ -188,0 +189,0 @@ }

@@ -354,3 +354,4 @@ "use strict";

: node.expression).end);
ctx.scriptLet.nestSnippetBlock(node.expression, closeParenIndex, snippetBlock, (id, params) => {
const scopeKind = parent.type === "Program" ? "snippet" : "render";
ctx.scriptLet.nestSnippetBlock(node.expression, closeParenIndex, snippetBlock, scopeKind, (id, params) => {
snippetBlock.id = id;

@@ -357,0 +358,0 @@ snippetBlock.params = params;

@@ -17,2 +17,3 @@ "use strict";

const body = ast.body;
const snippetChildren = [];
const fragment = (0, compat_1.getFragmentFromRoot)(svelteAst);

@@ -34,10 +35,18 @@ if (fragment) {

}
body.push(...(0, element_1.convertChildren)({ nodes: children }, ast, ctx));
const nonSnippetChildren = [];
for (const child of children) {
if (child.type === "SnippetBlock") {
snippetChildren.push(child);
}
else {
nonSnippetChildren.push(child);
}
}
body.push(...(0, element_1.convertChildren)({ nodes: nonSnippetChildren }, ast, ctx));
}
let script = null;
const instance = (0, compat_1.getInstanceFromRoot)(svelteAst);
if (instance) {
const script = Object.assign({ type: "SvelteScriptElement", name: null, startTag: null, body: [], endTag: null, parent: ast }, ctx.getConvertLocation(instance));
script = Object.assign({ type: "SvelteScriptElement", name: null, startTag: null, body: [], endTag: null, parent: ast }, ctx.getConvertLocation(instance));
extractAttributes(script, ctx);
if ((_a = ctx.parserOptions.svelteFeatures) === null || _a === void 0 ? void 0 : _a.experimentalGenerics)
convertGenericsAttribute(script, ctx);
(0, element_1.extractElementTags)(script, ctx, {

@@ -87,2 +96,5 @@ buildNameNode: (openTokenRange) => {

}
body.push(...(0, element_1.convertChildren)({ nodes: snippetChildren }, ast, ctx));
if (script && ((_a = ctx.parserOptions.svelteFeatures) === null || _a === void 0 ? void 0 : _a.experimentalGenerics))
convertGenericsAttribute(script, ctx);
// Set the scope of the Program node.

@@ -104,2 +116,3 @@ ctx.scriptLet.addProgramRestore((node, _tokens, _comments, { scopeManager, registerNodeToScope, addPostProcess }) => {

});
(0, sort_1.sortNodes)(body);
return ast;

@@ -106,0 +119,0 @@ }

@@ -6,3 +6,2 @@ "use strict";

const index_1 = require("./converts/index");
const sort_1 = require("./sort");
const __1 = require("..");

@@ -17,3 +16,2 @@ const svelte_version_1 = require("./svelte-version");

const ast = (0, index_1.convertSvelteRoot)(svelteAst, ctx);
(0, sort_1.sortNodes)(ast.body);
return {

@@ -20,0 +18,0 @@ ast,

@@ -14,3 +14,3 @@ import { VirtualTypeScriptContext } from "../context";

script: string;
generics: string;
rootScope: string;
render: string;

@@ -17,0 +17,0 @@ }, attrs: Record<string, string | undefined>, parserOptions: NormalizedParserOptions, context: AnalyzeTypeScriptContext): VirtualTypeScriptContext;

@@ -16,5 +16,5 @@ "use strict";

function analyzeTypeScriptInSvelte(code, attrs, parserOptions, context) {
const ctx = new context_1.VirtualTypeScriptContext(code.script + code.render + code.generics);
const ctx = new context_1.VirtualTypeScriptContext(code.script + code.render + code.rootScope);
ctx.appendOriginal(/^\s*/u.exec(code.script)[0].length);
const result = (0, script_1.parseScriptWithoutAnalyzeScope)(code.script + code.render + code.generics, attrs, Object.assign(Object.assign({}, parserOptions), {
const result = (0, script_1.parseScriptWithoutAnalyzeScope)(code.script + code.render + code.rootScope, attrs, Object.assign(Object.assign({}, parserOptions), {
// Without typings

@@ -21,0 +21,0 @@ project: null }));

@@ -10,3 +10,3 @@ import type { ESLintExtendedProgram } from "..";

render: string;
generics: string;
rootScope: string;
}, attrs: Record<string, string | undefined>, parserOptions: NormalizedParserOptions, context: AnalyzeTypeScriptContext): ESLintExtendedProgram;

@@ -13,0 +13,0 @@ /**

{
"name": "svelte-eslint-parser",
"version": "0.34.0-next.11",
"version": "0.34.0-next.12",
"description": "Svelte parser for ESLint",

@@ -89,3 +89,3 @@ "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git",

"svelte2tsx": "^0.7.3",
"typescript": "~5.3.3",
"typescript": "~5.4.0",
"typescript-eslint-parser-for-extra-files": "^0.6.0"

@@ -92,0 +92,0 @@ },

@@ -176,3 +176,3 @@ # svelte-eslint-parser

```json
```jsonc
{

@@ -182,3 +182,5 @@ "parser": "svelte-eslint-parser",

"svelteFeatures": {
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// Whether to parse the `generics` attribute.

@@ -185,0 +187,0 @@ // See https://github.com/sveltejs/rfcs/pull/38

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc