-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: account for sourcemap in meta info #8778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c917eb1
903ba2e
10aadf4
61ff4ea
a6ddb2d
f4108c0
db686cf
a03ec02
f0ff443
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'svelte': patch | ||
| --- | ||
|
|
||
| fix: account for preprocessor source maps when calculating meta info |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,135 +1,136 @@ | ||
| { | ||
| "name": "svelte", | ||
| "version": "4.0.0-next.2", | ||
| "description": "Cybernetically enhanced web apps", | ||
| "type": "module", | ||
| "module": "src/runtime/index.js", | ||
| "main": "src/runtime/index.js", | ||
| "files": [ | ||
| "src", | ||
| "types", | ||
| "compiler.*", | ||
| "register.js", | ||
| "index.d.ts", | ||
| "store.d.ts", | ||
| "animate.d.ts", | ||
| "transition.d.ts", | ||
| "easing.d.ts", | ||
| "motion.d.ts", | ||
| "action.d.ts", | ||
| "elements.d.ts", | ||
| "README.md" | ||
| ], | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": { | ||
| "types": "./types/index.d.ts", | ||
| "browser": { | ||
| "import": "./src/runtime/index.js" | ||
| }, | ||
| "import": "./src/runtime/ssr.js" | ||
| }, | ||
| "./compiler": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/compiler/index.js", | ||
| "require": "./compiler.cjs" | ||
| }, | ||
| "./action": { | ||
| "types": "./types/index.d.ts" | ||
| }, | ||
| "./animate": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/animate/index.js" | ||
| }, | ||
| "./easing": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/easing/index.js" | ||
| }, | ||
| "./internal": { | ||
| "import": "./src/runtime/internal/index.js" | ||
| }, | ||
| "./motion": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/motion/index.js" | ||
| }, | ||
| "./store": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/store/index.js" | ||
| }, | ||
| "./transition": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/transition/index.js" | ||
| }, | ||
| "./elements": { | ||
| "types": "./elements.d.ts" | ||
| } | ||
| }, | ||
| "engines": { | ||
| "node": ">=16" | ||
| }, | ||
| "types": "types/index.d.ts", | ||
| "scripts": { | ||
| "format": "prettier . --cache --plugin-search-dir=. --write", | ||
| "check": "prettier . --cache --plugin-search-dir=. --check", | ||
| "test": "vitest run && echo \"manually check that there are no type errors in test/types by opening the files in there\"", | ||
| "build": "rollup -c && pnpm types", | ||
| "generate:version": "node ./scripts/generate-version.js", | ||
| "dev": "rollup -cw", | ||
| "posttest": "agadoo src/internal/index.js", | ||
| "prepublishOnly": "pnpm build", | ||
| "types": "node ./scripts/generate-dts.js", | ||
| "lint": "eslint \"{src,test}/**/*.{ts,js}\" --cache" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/sveltejs/svelte.git", | ||
| "directory": "packages/svelte" | ||
| }, | ||
| "keywords": [ | ||
| "UI", | ||
| "framework", | ||
| "templates", | ||
| "templating" | ||
| ], | ||
| "author": "Rich Harris", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/sveltejs/svelte/issues" | ||
| }, | ||
| "homepage": "https://svelte.dev", | ||
| "dependencies": { | ||
| "@ampproject/remapping": "^2.2.1", | ||
| "@jridgewell/sourcemap-codec": "^1.4.15", | ||
| "acorn": "^8.8.2", | ||
| "aria-query": "^5.2.1", | ||
| "axobject-query": "^3.2.1", | ||
| "code-red": "^1.0.3", | ||
| "css-tree": "^2.3.1", | ||
| "estree-walker": "^3.0.3", | ||
| "is-reference": "^3.0.1", | ||
| "locate-character": "^3.0.0", | ||
| "magic-string": "^0.30.0", | ||
| "periscopic": "^3.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.34.3", | ||
| "@rollup/plugin-commonjs": "^24.1.0", | ||
| "@rollup/plugin-json": "^6.0.0", | ||
| "@rollup/plugin-node-resolve": "^15.0.2", | ||
| "@sveltejs/eslint-config": "^6.0.4", | ||
| "@types/aria-query": "^5.0.1", | ||
| "@types/estree": "^1.0.1", | ||
| "@types/node": "^14.14.31", | ||
| "agadoo": "^3.0.0", | ||
| "dts-buddy": "^0.1.7", | ||
| "esbuild": "^0.17.19", | ||
| "happy-dom": "^9.18.3", | ||
| "jsdom": "^21.1.1", | ||
| "kleur": "^4.1.5", | ||
| "rollup": "^3.20.2", | ||
| "source-map": "^0.7.4", | ||
| "tiny-glob": "^0.2.9", | ||
| "typescript": "^5.0.4", | ||
| "vitest": "^0.31.1" | ||
| } | ||
| } | ||
| "name": "svelte", | ||
| "version": "4.0.0-next.2", | ||
| "description": "Cybernetically enhanced web apps", | ||
| "type": "module", | ||
| "module": "src/runtime/index.js", | ||
| "main": "src/runtime/index.js", | ||
| "files": [ | ||
| "src", | ||
| "types", | ||
| "compiler.*", | ||
| "register.js", | ||
| "index.d.ts", | ||
| "store.d.ts", | ||
| "animate.d.ts", | ||
| "transition.d.ts", | ||
| "easing.d.ts", | ||
| "motion.d.ts", | ||
| "action.d.ts", | ||
| "elements.d.ts", | ||
| "README.md" | ||
| ], | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": { | ||
| "types": "./types/index.d.ts", | ||
| "browser": { | ||
| "import": "./src/runtime/index.js" | ||
| }, | ||
| "import": "./src/runtime/ssr.js" | ||
| }, | ||
| "./compiler": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/compiler/index.js", | ||
| "require": "./compiler.cjs" | ||
| }, | ||
| "./action": { | ||
| "types": "./types/index.d.ts" | ||
| }, | ||
| "./animate": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/animate/index.js" | ||
| }, | ||
| "./easing": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/easing/index.js" | ||
| }, | ||
| "./internal": { | ||
| "import": "./src/runtime/internal/index.js" | ||
| }, | ||
| "./motion": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/motion/index.js" | ||
| }, | ||
| "./store": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/store/index.js" | ||
| }, | ||
| "./transition": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./src/runtime/transition/index.js" | ||
| }, | ||
| "./elements": { | ||
| "types": "./elements.d.ts" | ||
| } | ||
| }, | ||
| "engines": { | ||
| "node": ">=16" | ||
| }, | ||
| "types": "types/index.d.ts", | ||
| "scripts": { | ||
| "format": "prettier . --cache --plugin-search-dir=. --write", | ||
| "check": "prettier . --cache --plugin-search-dir=. --check", | ||
| "test": "vitest run && echo \"manually check that there are no type errors in test/types by opening the files in there\"", | ||
| "build": "rollup -c && pnpm types", | ||
| "generate:version": "node ./scripts/generate-version.js", | ||
| "dev": "rollup -cw", | ||
| "posttest": "agadoo src/internal/index.js", | ||
| "prepublishOnly": "pnpm build", | ||
| "types": "node ./scripts/generate-dts.js", | ||
| "lint": "eslint \"{src,test}/**/*.{ts,js}\" --cache" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/sveltejs/svelte.git", | ||
| "directory": "packages/svelte" | ||
| }, | ||
| "keywords": [ | ||
| "UI", | ||
| "framework", | ||
| "templates", | ||
| "templating" | ||
| ], | ||
| "author": "Rich Harris", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/sveltejs/svelte/issues" | ||
| }, | ||
| "homepage": "https://svelte.dev", | ||
| "dependencies": { | ||
| "@ampproject/remapping": "^2.2.1", | ||
| "@jridgewell/sourcemap-codec": "^1.4.15", | ||
| "@jridgewell/trace-mapping": "^0.3.18", | ||
| "acorn": "^8.8.2", | ||
| "aria-query": "^5.2.1", | ||
| "axobject-query": "^3.2.1", | ||
| "code-red": "^1.0.3", | ||
| "css-tree": "^2.3.1", | ||
| "estree-walker": "^3.0.3", | ||
| "is-reference": "^3.0.1", | ||
| "locate-character": "^3.0.0", | ||
| "magic-string": "^0.30.0", | ||
| "periscopic": "^3.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.34.3", | ||
| "@rollup/plugin-commonjs": "^24.1.0", | ||
| "@rollup/plugin-json": "^6.0.0", | ||
| "@rollup/plugin-node-resolve": "^15.0.2", | ||
| "@sveltejs/eslint-config": "^6.0.4", | ||
| "@types/aria-query": "^5.0.1", | ||
| "@types/estree": "^1.0.1", | ||
| "@types/node": "^14.14.31", | ||
| "agadoo": "^3.0.0", | ||
| "dts-buddy": "^0.1.7", | ||
| "esbuild": "^0.17.19", | ||
| "happy-dom": "^9.18.3", | ||
| "jsdom": "^21.1.1", | ||
| "kleur": "^4.1.5", | ||
| "rollup": "^3.20.2", | ||
| "source-map": "^0.7.4", | ||
| "tiny-glob": "^0.2.9", | ||
| "typescript": "^5.0.4", | ||
| "vitest": "^0.31.1" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping'; | ||
| import { walk } from 'estree-walker'; | ||
| import { getLocator } from 'locate-character'; | ||
| import { reserved, is_valid } from '../utils/names.js'; | ||
|
|
@@ -142,9 +143,18 @@ export default class Component { | |
| /** @type {string} */ | ||
| file; | ||
|
|
||
| /** @type {(c: number) => { line: number; column: number }} */ | ||
| /** | ||
| * Use this for source mappings. Use `meta_locate` for the meta data on the dom elements. | ||
| * @type {(c: number) => { line: number; column: number }} | ||
| */ | ||
| locate; | ||
|
|
||
| /** | ||
| * Use this for the meta data on the dom elements. Use `locate` for source mappings. | ||
dummdidumm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @type {(c: number) => { line: number; column: number }} | ||
| */ | ||
| meta_locate; | ||
|
|
||
| /** @type {import('./nodes/Element.js').default[]} */ | ||
| elements = []; | ||
|
|
||
|
|
@@ -199,7 +209,21 @@ export default class Component { | |
| .replace(process.cwd(), '') | ||
| .replace(regex_leading_directory_separator, '') | ||
| : compile_options.filename); | ||
|
|
||
| // line numbers in stack trace frames are 1-based. source maps are 0-based | ||
| this.locate = getLocator(this.source, { offsetLine: 1 }); | ||
| // @ts-expect-error - fix the type of CompileOptions.sourcemap | ||
| const tracer = compile_options.sourcemap ? new TraceMap(compile_options.sourcemap) : undefined; | ||
| this.meta_locate = (c) => { | ||
| /** @type {{ line: number, column: number }} */ | ||
| let location = this.locate(c); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's confusing to me that we used a 1-based locator for we could make or we could make
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't change much as the source mapping function works on 1-based lines so we have back and forth either way. I think the way it's now is the most consistent (both locate and meta_locate are 1-based) and you do whatever you need to do on the consumer side (and 1-based is needed more often) |
||
| if (tracer) { | ||
| // originalPositionFor returns 1-based lines like locator | ||
| location = originalPositionFor(tracer, location); | ||
| } | ||
| return location; | ||
| }; | ||
|
|
||
| // styles | ||
| this.stylesheet = new Stylesheet({ | ||
| source, | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.