svelte-eslint-parser
Advanced tools
Comparing version 0.36.0 to 0.37.0
export declare const name = "svelte-eslint-parser"; | ||
export declare const version = "0.36.0"; | ||
export declare const version = "0.37.0"; |
@@ -8,2 +8,2 @@ "use strict"; | ||
exports.name = "svelte-eslint-parser"; | ||
exports.version = "0.36.0"; | ||
exports.version = "0.37.0"; |
@@ -121,2 +121,3 @@ "use strict"; | ||
function analyzePropsScope(body, scopeManager) { | ||
var _a; | ||
const moduleScope = scopeManager.scopes.find((scope) => scope.type === "module"); | ||
@@ -127,10 +128,36 @@ if (!moduleScope) { | ||
for (const node of body.body) { | ||
if (node.type !== "ExportNamedDeclaration") { | ||
continue; | ||
if (node.type === "ExportNamedDeclaration") { | ||
// Process for Svelte v4 style props. e.g. `export let x`; | ||
if (node.declaration) { | ||
if (node.declaration.type === "VariableDeclaration") { | ||
for (const decl of node.declaration.declarations) { | ||
for (const pattern of extractPattern(decl.id)) { | ||
if (pattern.type === "Identifier") { | ||
addPropReference(pattern, moduleScope); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
for (const spec of node.specifiers) { | ||
addPropReference(spec.local, moduleScope); | ||
} | ||
} | ||
} | ||
if (node.declaration) { | ||
if (node.declaration.type === "VariableDeclaration") { | ||
for (const decl of node.declaration.declarations) { | ||
if (decl.id.type === "Identifier") { | ||
addPropsReference(decl.id, moduleScope); | ||
else if (node.type === "VariableDeclaration") { | ||
// Process for Svelte v5 Runes props. e.g. `let { x = $bindable() } = $props()`; | ||
for (const decl of node.declarations) { | ||
if (((_a = decl.init) === null || _a === void 0 ? void 0 : _a.type) === "CallExpression" && | ||
decl.init.callee.type === "Identifier" && | ||
decl.init.callee.name === "$props" && | ||
decl.id.type === "ObjectPattern") { | ||
for (const pattern of extractPattern(decl.id)) { | ||
if (pattern.type === "AssignmentPattern" && | ||
pattern.left.type === "Identifier" && | ||
pattern.right.type === "CallExpression" && | ||
pattern.right.callee.type === "Identifier" && | ||
pattern.right.callee.name === "$bindable") { | ||
addPropReference(pattern.left, moduleScope); | ||
} | ||
} | ||
@@ -140,10 +167,37 @@ } | ||
} | ||
else { | ||
for (const spec of node.specifiers) { | ||
addPropsReference(spec.local, moduleScope); | ||
} | ||
function* extractPattern(node) { | ||
yield node; | ||
if (node.type === "Identifier") { | ||
return; | ||
} | ||
if (node.type === "ObjectPattern") { | ||
for (const prop of node.properties) { | ||
if (prop.type === "Property") { | ||
yield* extractPattern(prop.value); | ||
} | ||
else { | ||
yield* extractPattern(prop); | ||
} | ||
} | ||
return; | ||
} | ||
if (node.type === "ArrayPattern") { | ||
for (const elem of node.elements) { | ||
if (elem) { | ||
yield* extractPattern(elem); | ||
} | ||
} | ||
return; | ||
} | ||
if (node.type === "AssignmentPattern") { | ||
yield* extractPattern(node.left); | ||
return; | ||
} | ||
if (node.type === "RestElement") { | ||
yield* extractPattern(node.argument); | ||
} | ||
} | ||
/** Add virtual props reference */ | ||
function addPropsReference(node, scope) { | ||
/** Add virtual prop reference */ | ||
function addPropReference(node, scope) { | ||
for (const variable of scope.variables) { | ||
@@ -150,0 +204,0 @@ if (variable.name !== node.name) { |
export declare const globalsForRunes: readonly ["$state", "$derived", "$effect", "$props", "$bindable", "$inspect", "$host"]; | ||
export declare const globals: readonly ["$$slots", "$$props", "$$restProps"] | ("$$slots" | "$$props" | "$$restProps" | "$state" | "$derived" | "$effect" | "$props" | "$bindable" | "$inspect" | "$host")[]; | ||
export declare const globals: readonly ["$$slots", "$$props", "$$restProps"] | ("$props" | "$bindable" | "$$slots" | "$$props" | "$$restProps" | "$state" | "$derived" | "$effect" | "$inspect" | "$host")[]; | ||
export declare const globalsForSvelteScript: never[] | readonly ["$state", "$derived", "$effect", "$props", "$bindable", "$inspect", "$host"]; |
@@ -56,3 +56,3 @@ "use strict"; | ||
(0, analyze_scope_1.analyzeStoreScope)(resultScript.scopeManager); // for reactive vars | ||
(0, analyze_scope_1.analyzeSnippetsScope)(ctx.snippets, resultScript.scopeManager); // for reactive vars | ||
(0, analyze_scope_1.analyzeSnippetsScope)(ctx.snippets, resultScript.scopeManager); | ||
// Add $$xxx variable | ||
@@ -59,0 +59,0 @@ addGlobalVariables(resultScript.scopeManager, globals_1.globals); |
{ | ||
"name": "svelte-eslint-parser", | ||
"version": "0.36.0", | ||
"version": "0.37.0", | ||
"description": "Svelte parser for ESLint", | ||
@@ -45,4 +45,4 @@ "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git", | ||
"@changesets/changelog-github": "^0.5.0", | ||
"@changesets/cli": "^2.27.1", | ||
"@changesets/get-release-plan": "^4.0.0", | ||
"@changesets/cli": "^2.27.5", | ||
"@changesets/get-release-plan": "^4.0.2", | ||
"@ota-meshi/eslint-plugin": "^0.15.3", | ||
@@ -56,11 +56,11 @@ "@types/benchmark": "^2.1.5", | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.12.11", | ||
"@types/node": "^20.14.2", | ||
"@types/semver": "^7.5.8", | ||
"@typescript-eslint/eslint-plugin": "^7.8.0", | ||
"@typescript-eslint/parser": "~7.8.0", | ||
"@typescript-eslint/types": "~7.8.0", | ||
"@typescript-eslint/eslint-plugin": "^7.12.0", | ||
"@typescript-eslint/parser": "~7.12.0", | ||
"@typescript-eslint/types": "~7.12.0", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.4.1", | ||
"env-cmd": "^10.1.0", | ||
"esbuild": "^0.21.0", | ||
"esbuild": "^0.21.4", | ||
"esbuild-register": "^3.5.0", | ||
@@ -71,8 +71,8 @@ "eslint": "^8.57.0", | ||
"eslint-plugin-json-schema-validator": "^5.1.0", | ||
"eslint-plugin-jsonc": "^2.15.1", | ||
"eslint-plugin-n": "^17.5.1", | ||
"eslint-plugin-jsonc": "^2.16.0", | ||
"eslint-plugin-n": "^17.8.1", | ||
"eslint-plugin-node-dependencies": "^0.12.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-regexp": "^2.5.0", | ||
"eslint-plugin-svelte": "^2.38.0", | ||
"eslint-plugin-regexp": "^2.6.0", | ||
"eslint-plugin-svelte": "^2.39.2", | ||
"eslint-plugin-yml": "^1.14.0", | ||
@@ -84,12 +84,12 @@ "estree-walker": "^3.0.3", | ||
"mocha-chai-jest-snapshot": "^1.1.4", | ||
"nyc": "^15.1.0", | ||
"prettier": "~3.2.5", | ||
"nyc": "^17.0.0", | ||
"prettier": "~3.3.0", | ||
"prettier-plugin-pkg": "^0.18.1", | ||
"prettier-plugin-svelte": "^3.2.3", | ||
"rimraf": "^5.0.5", | ||
"semver": "^7.6.1", | ||
"svelte": "^5.0.0-next.125", | ||
"svelte2tsx": "^0.7.8", | ||
"prettier-plugin-svelte": "^3.2.4", | ||
"rimraf": "^5.0.7", | ||
"semver": "^7.6.2", | ||
"svelte": "^5.0.0-next.152", | ||
"svelte2tsx": "^0.7.9", | ||
"typescript": "~5.4.5", | ||
"typescript-eslint-parser-for-extra-files": "^0.6.0" | ||
"typescript-eslint-parser-for-extra-files": "^0.7.0" | ||
}, | ||
@@ -96,0 +96,0 @@ "publishConfig": { |
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
322132
7698