eslint-plugin-svelte3
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -0,1 +1,5 @@ | ||
# 2.2.1 | ||
- Handle `then` and `catch` scope in `{#await}` | ||
# 2.2.0 | ||
@@ -2,0 +6,0 @@ |
50
index.js
@@ -133,3 +133,19 @@ 'use strict'; | ||
/// PRE- AND POSTPROCESSING FUNCTIONS FOR SVELTE COMPONENTS /// | ||
// find the contextual name or names described by a particular node in the AST | ||
const contextual_names = []; | ||
const find_contextual_names = node => { | ||
if (node) { | ||
if (typeof node === 'string') { | ||
contextual_names.push(node); | ||
} else if (typeof node === 'object') { | ||
walk(node, { | ||
enter(node, parent, prop) { | ||
if (node.name && prop !== 'key') { | ||
contextual_names.push(node.name); | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -221,2 +237,3 @@ // extract scripts to lint from component definition | ||
// add expressions from template to the constructed string | ||
const nodes_with_contextual_scope = new WeakSet(); | ||
walk(ast.html, { | ||
@@ -227,17 +244,13 @@ enter(node, parent, prop) { | ||
} | ||
if (node.context && typeof node.context === 'object') { | ||
// find all the variables declared in this context | ||
const names = []; | ||
walk(node.context, { | ||
enter(node, parent, prop) { | ||
if (node.name && prop !== 'key') { | ||
names.push(node.name); | ||
} | ||
}, | ||
}); | ||
transformed_code += `{${names.map(name => `let ${name}=0;`).join('')}\n`; | ||
contextual_names.length = 0; | ||
find_contextual_names(node.context); | ||
if (node.type === 'EachBlock') { | ||
find_contextual_names(node.index); | ||
} else if (node.type === 'AwaitBlock') { | ||
find_contextual_names(node.value); | ||
find_contextual_names(node.error); | ||
} | ||
if (node.index && typeof node.index === 'string') { | ||
// declare the index variable, if present | ||
transformed_code += `{let ${node.index}=0;\n`; | ||
if (contextual_names.length) { | ||
nodes_with_contextual_scope.add(node); | ||
transformed_code += `{let ${contextual_names.map(name => `${name}=0`).join(',')};\n`; | ||
} | ||
@@ -252,9 +265,6 @@ if (node.expression && typeof node.expression === 'object') { | ||
leave(node) { | ||
// close nested scopes created for context or index | ||
if (node.context && typeof node.context === 'object') { | ||
// close contextual scope | ||
if (nodes_with_contextual_scope.has(node)) { | ||
transformed_code += '}'; | ||
} | ||
if (node.index && typeof node.index === 'string') { | ||
transformed_code += '}'; | ||
} | ||
}, | ||
@@ -261,0 +271,0 @@ }); |
{ | ||
"name": "eslint-plugin-svelte3", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "An ESLint plugin for Svelte v3 components.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
20428
325