Socket
Socket
Sign inDemoInstall

svelte-eslint-parser

Package Overview
Dependencies
Maintainers
4
Versions
111
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.33.1 to 0.34.0-next.0

2

lib/meta.d.ts
export declare const name: "svelte-eslint-parser";
export declare const version: "0.33.1";
export declare const version: "0.34.0-next.0";

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

exports.name = "svelte-eslint-parser";
exports.version = "0.33.1";
exports.version = "0.34.0-next.0";

@@ -6,3 +6,3 @@ import type { SvelteAwaitBlock, SvelteAwaitCatchBlock, SvelteAwaitPendingBlock, SvelteAwaitThenBlock, SvelteConstTag, SvelteDebugTag, SvelteEachBlock, SvelteElement, SvelteElseBlockAlone, SvelteHTMLComment, SvelteIfBlock, SvelteIfBlockAlone, SvelteKeyBlock, SvelteMustacheTag, SvelteProgram, SvelteScriptElement, SvelteStyleElement, SvelteText } from "../../ast";

export declare function convertChildren(fragment: {
children: SvAST.TemplateNode[];
children?: SvAST.TemplateNode[];
}, parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock, ctx: Context): IterableIterator<SvelteText | SvelteElement | SvelteMustacheTag | SvelteDebugTag | SvelteConstTag | SvelteIfBlockAlone | SvelteEachBlock | SvelteAwaitBlock | SvelteKeyBlock | SvelteHTMLComment>;

@@ -9,0 +9,0 @@ /** Extract element tag and tokens */

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

fragment, parent, ctx) {
if (!fragment.children)
return;
for (const child of fragment.children) {

@@ -136,2 +138,4 @@ if (child.type === "Comment") {

function needScopeByChildren(fragment) {
if (!fragment.children)
return false;
for (const child of fragment.children) {

@@ -281,45 +285,60 @@ if (child.type === "ConstTag") {

const valueStartIndex = (0, common_1.indexOf)(ctx.code, (c) => Boolean(c.trim()), eqIndex + 1);
const quote = ctx.code.startsWith(thisValue, valueStartIndex)
? null
: ctx.code[valueStartIndex];
const literalStartIndex = quote
? valueStartIndex + quote.length
: valueStartIndex;
const literalEndIndex = literalStartIndex + thisValue.length;
const endIndex = quote ? literalEndIndex + quote.length : literalEndIndex;
const thisAttr = Object.assign({ type: "SvelteAttribute", key: null, boolean: false, value: [], parent: element.startTag }, ctx.getConvertLocation({ start: startIndex, end: endIndex }));
thisAttr.key = Object.assign({ type: "SvelteName", name: "this", parent: thisAttr }, ctx.getConvertLocation({ start: startIndex, end: eqIndex }));
thisAttr.value.push(Object.assign({ type: "SvelteLiteral", value: thisValue, parent: thisAttr }, ctx.getConvertLocation({
start: literalStartIndex,
end: literalEndIndex,
})));
// this
ctx.addToken("HTMLIdentifier", {
start: startIndex,
end: startIndex + 4,
});
// =
ctx.addToken("Punctuator", {
start: eqIndex,
end: eqIndex + 1,
});
if (quote) {
// "
ctx.addToken("Punctuator", {
start: valueStartIndex,
end: literalStartIndex,
if (ctx.code[valueStartIndex] === "{") {
// Svelte v5 `this={"..."}`
const openingQuoteIndex = (0, common_1.indexOf)(ctx.code, (c) => c === '"' || c === "'", valueStartIndex + 1);
const quote = ctx.code[openingQuoteIndex];
const closingQuoteIndex = (0, common_1.indexOf)(ctx.code, (c) => c === quote, openingQuoteIndex + thisValue.length);
const closeIndex = ctx.code.indexOf("}", closingQuoteIndex + 1);
const endIndex = (0, common_1.indexOf)(ctx.code, (c) => c === ">" || !c.trim(), closeIndex);
thisNode = createSvelteSpecialDirective(startIndex, endIndex, eqIndex, {
type: "Literal",
value: thisValue,
range: [openingQuoteIndex, closingQuoteIndex + 1],
});
}
ctx.addToken("HTMLText", {
start: literalStartIndex,
end: literalEndIndex,
});
if (quote) {
// "
else {
const quote = ctx.code.startsWith(thisValue, valueStartIndex)
? null
: ctx.code[valueStartIndex];
const literalStartIndex = quote
? valueStartIndex + quote.length
: valueStartIndex;
const literalEndIndex = literalStartIndex + thisValue.length;
const endIndex = quote ? literalEndIndex + quote.length : literalEndIndex;
const thisAttr = Object.assign({ type: "SvelteAttribute", key: null, boolean: false, value: [], parent: element.startTag }, ctx.getConvertLocation({ start: startIndex, end: endIndex }));
thisAttr.key = Object.assign({ type: "SvelteName", name: "this", parent: thisAttr }, ctx.getConvertLocation({ start: startIndex, end: eqIndex }));
thisAttr.value.push(Object.assign({ type: "SvelteLiteral", value: thisValue, parent: thisAttr }, ctx.getConvertLocation({
start: literalStartIndex,
end: literalEndIndex,
})));
// this
ctx.addToken("HTMLIdentifier", {
start: startIndex,
end: startIndex + 4,
});
// =
ctx.addToken("Punctuator", {
start: literalEndIndex,
end: endIndex,
start: eqIndex,
end: eqIndex + 1,
});
if (quote) {
// "
ctx.addToken("Punctuator", {
start: valueStartIndex,
end: literalStartIndex,
});
}
ctx.addToken("HTMLText", {
start: literalStartIndex,
end: literalEndIndex,
});
if (quote) {
// "
ctx.addToken("Punctuator", {
start: literalEndIndex,
end: endIndex,
});
}
thisNode = thisAttr;
}
thisNode = thisAttr;
}

@@ -332,2 +351,13 @@ else {

const endIndex = (0, common_1.indexOf)(ctx.code, (c) => c === ">" || !c.trim(), closeIndex);
thisNode = createSvelteSpecialDirective(startIndex, endIndex, eqIndex, thisValue);
}
const targetIndex = element.startTag.attributes.findIndex((attr) => thisNode.range[1] <= attr.range[0]);
if (targetIndex === -1) {
element.startTag.attributes.push(thisNode);
}
else {
element.startTag.attributes.splice(targetIndex, 0, thisNode);
}
/** Create SvelteSpecialDirective */
function createSvelteSpecialDirective(startIndex, endIndex, eqIndex, expression) {
const thisDir = Object.assign({ type: "SvelteSpecialDirective", kind: "this", key: null, expression: null, parent: element.startTag }, ctx.getConvertLocation({ start: startIndex, end: endIndex }));

@@ -345,14 +375,7 @@ thisDir.key = Object.assign({ type: "SvelteSpecialDirectiveKey", parent: thisDir }, ctx.getConvertLocation({ start: startIndex, end: eqIndex }));

});
ctx.scriptLet.addExpression(thisValue, thisDir, null, (es) => {
ctx.scriptLet.addExpression(expression, thisDir, null, (es) => {
thisDir.expression = es;
});
thisNode = thisDir;
return thisDir;
}
const targetIndex = element.startTag.attributes.findIndex((attr) => thisNode.range[1] <= attr.range[0]);
if (targetIndex === -1) {
element.startTag.attributes.push(thisNode);
}
else {
element.startTag.attributes.splice(targetIndex, 0, thisNode);
}
}

@@ -359,0 +382,0 @@ /** Find the start index of `this` */

@@ -141,3 +141,3 @@ import type ESTree from "estree";

name: "svelte:options";
children: TemplateNode[];
children?: TemplateNode[];
attributes: AttributeOrDirective[];

@@ -144,0 +144,0 @@ }

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

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

"peerDependencies": {
"svelte": "^3.37.0 || ^4.0.0"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.2"
},

@@ -47,3 +47,3 @@ "peerDependenciesMeta": {

"@changesets/get-release-plan": "^3.0.16",
"@ota-meshi/eslint-plugin": "^0.15.0",
"@ota-meshi/eslint-plugin": "^0.15.2",
"@types/benchmark": "^2.1.2",

@@ -56,7 +56,7 @@ "@types/chai": "^4.3.5",

"@types/mocha": "^10.0.1",
"@types/node": "^18.16.16",
"@types/node": "^20.0.0",
"@types/semver": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "~6.7.0",
"@typescript-eslint/types": "~6.7.0",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "~6.10.0",
"@typescript-eslint/types": "~6.10.0",
"benchmark": "^2.1.4",

@@ -75,3 +75,3 @@ "chai": "^4.3.7",

"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-regexp": "^1.15.0",
"eslint-plugin-regexp": "^2.0.0",
"eslint-plugin-svelte": "^2.30.0",

@@ -85,3 +85,3 @@ "eslint-plugin-yml": "^1.7.0",

"nyc": "^15.1.0",
"prettier": "^3.0.0",
"prettier": "~3.1.0",
"prettier-plugin-pkg": "^0.18.0",

@@ -91,4 +91,4 @@ "prettier-plugin-svelte": "^3.0.0",

"semver": "^7.5.1",
"svelte": "^4.2.0",
"svelte2tsx": "^0.6.20",
"svelte": "^5.0.0-next.2",
"svelte2tsx": "^0.6.25",
"typescript": "~5.1.3",

@@ -95,0 +95,0 @@ "typescript-eslint-parser-for-extra-files": "^0.5.0"

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