Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sveltejs/svelte-eslint-parser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.30.0
Choose a base ref
...
head repository: sveltejs/svelte-eslint-parser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.31.0
Choose a head ref
  • 9 commits
  • 43 files changed
  • 5 contributors

Commits on Jun 5, 2023

  1. Copy the full SHA
    4cc8f89 View commit details
  2. Copy the full SHA
    b8435a1 View commit details

Commits on Jun 10, 2023

  1. fix: CI error with svelte v4-next.1 (#349)

    * fix: CI error with svelte v4.next.1
    
    * format
    ota-meshi authored Jun 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2437a81 View commit details
  2. Added style AST to parser services (#340)

    * Added postcss and postcss-scss as dependencies
    
    * Parsing style AST as part of parser services
    
    * Added a JSDoc for parseStyleAst, removed commented out code
    
    * Added a changeset for PostCSS AST with parser services
    
    * Wrapped style AST in StyleContext
    
    * Logging postcss parse error to StyleContext
    
    * Moved style constext parsing to own file
    
    * Fixed PostCSS node locations
    
    * Not logging PostCSS errors for now
    
    * Using a discriminated union for StyleContext
    
    * Including parsing errors in StyleContext
    
    * Added infrastructure for style-context tests
    
    * Added a test with self-closing style element
    
    * Not printing file name in style-context test fixtures
    
    * Passing style element to fixPostCSSNodeLocation
    
    * Fixed column offset on style root node
    
    * Added a PostCSS AST test with simple CSS
    
    * Added a PostCSS AST test with empty <style> element
    
    * Fixed column offset in one-line styles
    
    * Added a test for one-line style
    
    * Ignoring another possible filename location in style-context tests
    
    * Added tests with invalid style
    
    * Added tests with unknown style lang
    
    * Added a test for parsing SCSS
    
    * Added a test with unrelated style attribute
    
    * ESLint fix
    
    * Added a converter functions for ESTree-style range and location for PostCSS nodes
    
    * Fixed incorrect Range conversion
    
    * Added tests for converter functions for ESTree-style range and location for PostCSS nodes
    
    * Exposing the StyleContext interface
    
    * Exposing styleNodeLoc and styleNodeRange functions as part of the parser services
    
    ---------
    
    Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
    marekdedic and ota-meshi authored Jun 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d170f91 View commit details
  3. chore(deps): update coverallsapp/github-action action to v2.2.0 (#350)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3282048 View commit details
  4. chore(deps): update dependency esbuild to ^0.18.0 (#351)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9e6c32d View commit details
  5. chore(deps): update dependency monaco-editor to v0.39.0 (#352)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    37dda48 View commit details
  6. fix: crash when using component and {@const} (#354)

    * fix: crash when using component and `{@const}`
    
    * Create curly-turkeys-appear.md
    ota-meshi authored Jun 10, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ff24f99 View commit details

Commits on Jun 11, 2023

  1. chore: release svelte-eslint-parser (#353)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jun 11, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    21601c6 View commit details
Showing with 3,301 additions and 80 deletions.
  1. +1 −1 .github/workflows/NodeCI.yml
  2. +10 −0 CHANGELOG.md
  3. +1 −1 explorer-v2/src/app.html
  4. +40 −39 package.json
  5. +27 −27 src/context/script-let.ts
  6. +8 −3 src/index.ts
  7. +1 −1 src/meta.ts
  8. +30 −0 src/parser/index.ts
  9. +145 −0 src/parser/style-context.ts
  10. +1 −0 src/parser/template.ts
  11. +8 −0 tests/fixtures/parser/ast/at-const01-within-component-input.svelte
  12. +1,198 −0 tests/fixtures/parser/ast/at-const01-within-component-output.json
  13. +810 −0 tests/fixtures/parser/ast/at-const01-within-component-scope-output.json
  14. +2 −2 tests/fixtures/parser/ast/ts-event02-type-output.svelte
  15. +2 −2 tests/fixtures/parser/ast/ts-event05-type-output.svelte
  16. +1 −1 tests/fixtures/parser/ast/ts-reactive02-type-output.svelte
  17. +1 −1 tests/fixtures/parser/ast/ts-reactive05-type-output.svelte
  18. +1 −1 tests/fixtures/parser/ast/ts-store01-type-output.svelte
  19. +1 −1 tests/fixtures/parser/ast/ts-store02-type-output.svelte
  20. +7 −0 tests/fixtures/parser/style-context/empty-style-element-input.svelte
  21. +27 −0 tests/fixtures/parser/style-context/empty-style-element-output.json
  22. +5 −0 tests/fixtures/parser/style-context/no-style-element-input.svelte
  23. +3 −0 tests/fixtures/parser/style-context/no-style-element-output.json
  24. +7 −0 tests/fixtures/parser/style-context/one-line-css-input.svelte
  25. +78 −0 tests/fixtures/parser/style-context/one-line-css-output.json
  26. +17 −0 tests/fixtures/parser/style-context/parse-error-input.svelte
  27. +20 −0 tests/fixtures/parser/style-context/parse-error-output.json
  28. +7 −0 tests/fixtures/parser/style-context/self-closing-style-element-input.svelte
  29. +3 −0 tests/fixtures/parser/style-context/self-closing-style-element-output.json
  30. +17 −0 tests/fixtures/parser/style-context/simple-css-input.svelte
  31. +127 −0 tests/fixtures/parser/style-context/simple-css-output.json
  32. +18 −0 tests/fixtures/parser/style-context/simple-scss-input.svelte
  33. +178 −0 tests/fixtures/parser/style-context/simple-scss-output.json
  34. +17 −0 tests/fixtures/parser/style-context/unknown-lang-input.svelte
  35. +4 −0 tests/fixtures/parser/style-context/unknown-lang-output.json
  36. +17 −0 tests/fixtures/parser/style-context/unrelated-style-attr-input.svelte
  37. +127 −0 tests/fixtures/parser/style-context/unrelated-style-attr-output.json
  38. +17 −0 tests/fixtures/parser/style-location-converter/simple-css-input.svelte
  39. +78 −0 tests/fixtures/parser/style-location-converter/simple-css-output.json
  40. +18 −0 tests/fixtures/parser/style-location-converter/simple-scss-input.svelte
  41. +110 −0 tests/fixtures/parser/style-location-converter/simple-scss-output.json
  42. +51 −0 tests/src/parser/style-context.ts
  43. +60 −0 tests/src/parser/style-location-coverter.ts
2 changes: 1 addition & 1 deletion .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
@@ -122,6 +122,6 @@ jobs:
- name: Test
run: pnpm run cover
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2.1.2
uses: coverallsapp/github-action@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# svelte-eslint-parser

## 0.31.0

### Minor Changes

- [#340](https://github.com/sveltejs/svelte-eslint-parser/pull/340) [`d170f91`](https://github.com/sveltejs/svelte-eslint-parser/commit/d170f915c6133aa42f6d3d1c9fb7bc81269f77eb) Thanks [@marekdedic](https://github.com/marekdedic)! - added PostCSS AST of styles to parser services

### Patch Changes

- [#354](https://github.com/sveltejs/svelte-eslint-parser/pull/354) [`ff24f99`](https://github.com/sveltejs/svelte-eslint-parser/commit/ff24f99d70a97ec13c05459314c08da4f29546eb) Thanks [@ota-meshi](https://github.com/ota-meshi)! - fix: crash when using component and `{@const}`

## 0.30.0

### Minor Changes
2 changes: 1 addition & 1 deletion explorer-v2/src/app.html
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />

%sveltekit.head%
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.38.0/min/vs/loader.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.39.0/min/vs/loader.min.js"></script>
</head>
<body>
<div id="svelte">%sveltekit.body%</div>
79 changes: 40 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-eslint-parser",
"version": "0.30.0",
"version": "0.31.0",
"description": "Svelte parser for ESLint",
"repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git",
"homepage": "https://github.com/sveltejs/svelte-eslint-parser#readme",
@@ -10,7 +10,7 @@
],
"funding": "https://github.com/sponsors/ota-meshi",
"license": "MIT",
"packageManager": "pnpm@7.32.5",
"packageManager": "pnpm@7.33.0",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
@@ -55,57 +55,58 @@
"dependencies": {
"eslint-scope": "^7.0.0",
"eslint-visitor-keys": "^3.0.0",
"espree": "^9.0.0"
"espree": "^9.0.0",
"postcss": "^8.4.23",
"postcss-scss": "^4.0.6"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.2",
"@changesets/get-release-plan": "^3.0.0",
"@ota-meshi/eslint-plugin": "^0.13.0",
"@types/benchmark": "^2.1.1",
"@types/chai": "^4.3.0",
"@types/eslint": "^8.0.0",
"@types/eslint-scope": "^3.7.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@changesets/get-release-plan": "^3.0.16",
"@ota-meshi/eslint-plugin": "^0.13.7",
"@types/benchmark": "^2.1.2",
"@types/chai": "^4.3.5",
"@types/eslint": "^8.40.1",
"@types/eslint-scope": "^3.7.4",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/estree": "^1.0.0",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.0",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "~5.59.0",
"@typescript-eslint/types": "^5.59.5",
"@types/estree": "^1.0.1",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.16",
"@types/semver": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "~5.59.9",
"@typescript-eslint/types": "^5.59.9",
"benchmark": "^2.1.4",
"chai": "^4.3.4",
"chai": "^4.3.7",
"env-cmd": "^10.1.0",
"esbuild": "^0.17.0",
"esbuild-register": "^3.3.3",
"eslint": "^8.2.0",
"esbuild": "^0.18.0",
"esbuild-register": "^3.4.2",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-json-schema-validator": "^4.0.0",
"eslint-plugin-jsonc": "^2.0.0",
"eslint-plugin-json-schema-validator": "^4.5.0",
"eslint-plugin-jsonc": "^2.8.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-node-dependencies": "^0.11.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-regexp": "^1.5.0",
"eslint-plugin-svelte": "^2.28.0",
"eslint-plugin-yml": "^1.0.0",
"estree-walker": "^3.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-regexp": "^1.15.0",
"eslint-plugin-svelte": "^2.30.0",
"eslint-plugin-yml": "^1.7.0",
"estree-walker": "^3.0.3",
"locate-character": "^2.0.5",
"magic-string": "^0.30.0",
"mocha": "^10.0.0",
"mocha-chai-jest-snapshot": "^1.1.3",
"mocha": "^10.2.0",
"mocha-chai-jest-snapshot": "^1.1.4",
"nyc": "^15.1.0",
"prettier": "^2.8.0",
"prettier-plugin-pkg": "^0.17.0",
"prettier": "^2.8.8",
"prettier-plugin-pkg": "^0.17.1",
"prettier-plugin-svelte": "^2.10.1",
"rimraf": "^5.0.0",
"semver": "^7.3.5",
"svelte": "^4.0.0-0",
"rimraf": "^5.0.1",
"semver": "^7.5.1",
"svelte": "^4.0.0-next.1",
"svelte2tsx": "^0.6.15",
"typescript": "~5.0.0",
"typescript-eslint-parser-for-extra-files": "^0.5.0",
"vue-eslint-parser": "^9.0.0"
"typescript": "~5.1.3",
"typescript-eslint-parser-for-extra-files": "^0.5.0"
},
"publishConfig": {
"access": "public"
54 changes: 27 additions & 27 deletions src/context/script-let.ts
Original file line number Diff line number Diff line change
@@ -423,7 +423,33 @@ export class ScriptLetContext {
preparationScript?: string[];
})
): void {
if (!params) {
let resolvedParams;
if (typeof params === "function") {
if (this.ctx.isTypeScript()) {
const generatedTypes = params({
generateUniqueId: (base) => this.generateUniqueId(base),
});
resolvedParams = [generatedTypes.param];
if (generatedTypes.preparationScript) {
for (const preparationScript of generatedTypes.preparationScript) {
this.appendScriptWithoutOffset(
preparationScript,
(node, tokens, comments, result) => {
tokens.length = 0;
comments.length = 0;
removeAllScopeAndVariableAndReference(node, result);
}
);
}
}
} else {
const generatedTypes = params(null);
resolvedParams = [generatedTypes.param];
}
} else {
resolvedParams = params;
}
if (!resolvedParams || resolvedParams.length === 0) {
const restore = this.appendScript(
`{`,
block.range[0],
@@ -442,32 +468,6 @@ export class ScriptLetContext {
);
this.pushScope(restore, "}");
} else {
let resolvedParams;
if (typeof params === "function") {
if (this.ctx.isTypeScript()) {
const generatedTypes = params({
generateUniqueId: (base) => this.generateUniqueId(base),
});
resolvedParams = [generatedTypes.param];
if (generatedTypes.preparationScript) {
for (const preparationScript of generatedTypes.preparationScript) {
this.appendScriptWithoutOffset(
preparationScript,
(node, tokens, comments, result) => {
tokens.length = 0;
comments.length = 0;
removeAllScopeAndVariableAndReference(node, result);
}
);
}
}
} else {
const generatedTypes = params(null);
resolvedParams = [generatedTypes.param];
}
} else {
resolvedParams = params;
}
const sortedParams = [...resolvedParams]
.map((d) => {
return {
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { parseForESLint } from "./parser";
import * as AST from "./ast";
import { traverseNodes } from "./traverse";
import { KEYS } from "./visitor-keys";
import { ParseError } from "./errors";
export {
parseForESLint,
StyleContext,
StyleContextNoStyleElement,
StyleContextParseError,
StyleContextSuccess,
StyleContextUnknownLang,
} from "./parser";
export * as meta from "./meta";
export { name } from "./meta";

export { AST, ParseError };

// parser
export { parseForESLint };
// Keys
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore
export const VisitorKeys = KEYS;
2 changes: 1 addition & 1 deletion src/meta.ts
Original file line number Diff line number Diff line change
@@ -2,4 +2,4 @@
// This file has been automatically generated,
// in order to update its content execute "pnpm run build:meta"
export const name = "svelte-eslint-parser" as const;
export const version = "0.30.0" as const;
export const version = "0.31.0" as const;
30 changes: 30 additions & 0 deletions src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import type {
Comment,
SvelteProgram,
SvelteScriptElement,
SvelteStyleElement,
Token,
} from "../ast";
import type { Program } from "estree";
@@ -21,6 +22,24 @@ import {
import { ParseError } from "../errors";
import { parseTypeScript } from "./typescript";
import { addReference } from "../scope";
import {
parseStyleContext,
type StyleContext,
type StyleContextNoStyleElement,
type StyleContextParseError,
type StyleContextSuccess,
type StyleContextUnknownLang,
styleNodeLoc,
styleNodeRange,
} from "./style-context";

export {
StyleContext,
StyleContextNoStyleElement,
StyleContextParseError,
StyleContextSuccess,
StyleContextUnknownLang,
};

export interface ESLintProgram extends Program {
comments: Comment[];
@@ -50,6 +69,7 @@ export function parseForESLint(
services: Record<string, any> & {
isSvelte: true;
getSvelteHtmlAst: () => SvAST.Fragment;
getStyleContext: () => StyleContext;
};
visitorKeys: { [type: string]: string[] };
scopeManager: ScopeManager;
@@ -166,12 +186,22 @@ export function parseForESLint(
);
}

const styleElement = ast.body.find(
(b): b is SvelteStyleElement => b.type === "SvelteStyleElement"
);
const styleContext = parseStyleContext(styleElement, ctx);

resultScript.ast = ast as any;
resultScript.services = Object.assign(resultScript.services || {}, {
isSvelte: true,
getSvelteHtmlAst() {
return resultTemplate.svelteAst.html;
},
getStyleContext() {
return styleContext;
},
styleNodeLoc,
styleNodeRange,
});
resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys);

Loading