Skip to content

Commit 45ff2e4

Browse files
committed
Bug fixed for self closing tags (0.1.6-beta)
1 parent 5cfedd1 commit 45ff2e4

File tree

4 files changed

+83
-41
lines changed

4 files changed

+83
-41
lines changed

CHANGELOG.md

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,49 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Work towards making it stable.
1212
- Add the related file name too below the colored overlay.
1313

14+
## [0.1.6-beta] - 31st Aug 2025
15+
16+
### Added
17+
18+
Nothing added.
19+
20+
### Technical Improvements
21+
22+
Nothing improved.
23+
24+
### Changed
25+
26+
- Added LICENSE, README, and package.json to dist/ on build.
27+
28+
### Fixed
29+
30+
- Bug fixes for self closing tags.
31+
1432
## [0.1.5-beta] - 30th Aug 2025
1533

1634
### Added
1735

18-
- **Click to Open in VS Code**: Ctrl/Cmd + Click functionality to instantly open source files in VS Code
19-
- **Automatic Client-side Script Injection**: Zero-configuration setup with automatic script injection for click-to-open functionality
20-
- **Base64 Metadata Encoding**: Implemented base64 encoding for `data-svelte-trace` attributes
21-
- **Configuration Options**: Added `openInCode` configuration option to control client-side script injection
22-
- **VS Code Integration**: Seamless integration with VS Code through `vscode://` protocol links
23-
- **Enhanced User Experience**: Instant navigation from browser elements to source code with precise line and column positioning
36+
- **Click to Open in VS Code**: Ctrl/Cmd + Click functionality to instantly open source files in VS Code.
37+
- **Automatic Client-side Script Injection**: Zero-configuration setup with automatic script injection for click-to-open functionality.
38+
- **Base64 Metadata Encoding**: Implemented base64 encoding for `data-svelte-trace` attributes.
39+
- **Configuration Options**: Added `openInCode` configuration option to control client-side script injection.
40+
- **VS Code Integration**: Seamless integration with VS Code through `vscode://` protocol links.
41+
- **Enhanced User Experience**: Instant navigation from browser elements to source code with precise line and column positioning.
2442

2543
### Technical Improvements
2644

27-
- Client-side event listener for `Ctrl/Cmd` + `Click` detection
28-
- Base64 encoding/decoding for metadata security and cleanliness
29-
- Configurable preprocessor options
30-
- VS Code protocol URL construction for direct editor opening
31-
- Improved metadata handling and parsing
45+
- Client-side event listener for `Ctrl/Cmd` + `Click` detection.
46+
- Base64 encoding/decoding for metadata security and cleanliness.
47+
- Configurable preprocessor options.
48+
- VS Code protocol URL construction for direct editor opening.
49+
- Improved metadata handling and parsing.
3250

3351
### Changed
3452

35-
- Made code modular, and more readable
36-
- Metadata format now uses base64 encoding for cleaner HTML output
37-
- Enhanced preprocessor configuration system
38-
- Improved documentation with comprehensive setup guide
53+
- Made code modular, and more readable.
54+
- Metadata format now uses base64 encoding for cleaner HTML output.
55+
- Enhanced preprocessor configuration system.
56+
- Improved documentation with comprehensive setup guide.
3957

4058
### Fixed
4159

@@ -45,29 +63,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4563

4664
### Added
4765

48-
- Initial beta release
49-
- Svelte 5 preprocessor functionality
50-
- `data-svelte-trace` attribute injection
51-
- Support for all HTML elements in Svelte components
52-
- Class attribute position tracking
53-
- File path metadata inclusion
54-
- Support for complex Svelte blocks (if, each, await, key, snippet)
55-
- Integration with SvelteKit and Vite
66+
- Initial beta release.
67+
- Svelte 5 preprocessor functionality.
68+
- `data-svelte-trace` attribute injection.
69+
- Support for all HTML elements in Svelte components.
70+
- Class attribute position tracking.
71+
- File path metadata inclusion.
72+
- Support for complex Svelte blocks (if, each, await, key, snippet).
73+
- Integration with SvelteKit and Vite.
5674

5775
### Technical Details
5876

59-
- Uses magic-string for efficient code manipulation
60-
- Parses Svelte AST to identify HTML elements
61-
- Excludes script and style tags from processing
62-
- Handles elements with and without existing attributes
63-
- Tracks class attribute start/end positions
77+
- Uses magic-string for efficient code manipulation.
78+
- Parses Svelte AST to identify HTML elements.
79+
- Excludes script and style tags from processing.
80+
- Handles elements with and without existing attributes.
81+
- Tracks class attribute start/end positions.
6482

6583
### Known Limitations
6684

67-
- Metadata is not base64 encoded yet
68-
- Limited testing with complex Svelte features
69-
- No configuration options
70-
- Terrible code quality
85+
- Metadata is not base64 encoded yet.
86+
- Limited testing with complex Svelte features.
87+
- No configuration options.
88+
- Terrible code quality.
7189

7290
[Unreleased]: https://github.com/Git002/svelte-trace/compare/v0.1.5-beta...HEAD
7391
[0.1.5-beta]: https://github.com/Git002/svelte-trace/compare/v0.1.0-beta.1...v0.1.5-beta

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-trace",
3-
"version": "0.1.5-beta.2",
3+
"version": "0.1.6-beta",
44
"description": "svelte-trace is a Svelte 5 preprocessor that enables 'click-to-open VS Code' functionality by adding metadata to HTML elements.",
55
"type": "module",
66
"main": "./dist/index.js",
@@ -12,7 +12,10 @@
1212
}
1313
},
1414
"files": [
15-
"dist"
15+
"dist",
16+
"README.md",
17+
"LICENSE",
18+
"package.json"
1619
],
1720
"keywords": [
1821
"svelte-trace",
@@ -55,7 +58,8 @@
5558
"clean": "rm -rf dist",
5659
"build:ts": "tsc -p tsconfig.build.json",
5760
"build:assets": "cp -r src/assets dist/",
58-
"build": "npm run clean && npm run build:ts && npm run build:assets",
61+
"build:docs": "cp README.md LICENSE package.json dist/",
62+
"build": "npm run clean && npm run build:ts && npm run build:assets && npm run build:docs",
5963
"test": "echo 'Tests coming soon'",
6064
"prepublishOnly": "npm run build"
6165
}

src/processors/core_processor.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ export function processNodes(filepath: string, content: string, ast: AST.Root):
2323
*/
2424
const addDataAttribute = (node: AST.RegularElement): void => {
2525
if (node.type !== "RegularElement") return;
26-
if (node.name === "script" || node.name === "style") return;
26+
if (
27+
node.name === "script" ||
28+
node.name === "style" ||
29+
node.name === "meta" ||
30+
node.name === "link" ||
31+
node.name === "title"
32+
)
33+
return;
2734

2835
const classAttr = node.attributes.find(
2936
(attr): attr is AST.Attribute => attr.type === "Attribute" && attr.name === "class"
@@ -39,9 +46,21 @@ export function processNodes(filepath: string, content: string, ast: AST.Root):
3946
const encodedBase64Data = Buffer.from(dataAttrValue, "utf8").toString("base64");
4047
const dataAttribute = `data-svelte-trace="${encodedBase64Data}"`;
4148

42-
// Always insert before the closing '>' to make it the last attribute
43-
const tagEnd = content.indexOf(">", node.start);
44-
magicString.appendLeft(tagEnd, ` ${dataAttribute}`);
49+
// Find the correct insertion point based on whether it's self-closing or not
50+
let insertionPoint: number;
51+
52+
// If there are attributes, insert after the last attribute
53+
if (node.attributes.length > 0) {
54+
const lastAttr = node.attributes[node.attributes.length - 1];
55+
insertionPoint = lastAttr.end;
56+
}
57+
// If no attributes, insert after the tag name. Included +1 for '<'
58+
else {
59+
const tagNameEnd = node.start + 1 + node.name.length;
60+
insertionPoint = tagNameEnd;
61+
}
62+
63+
magicString.appendLeft(insertionPoint, ` ${dataAttribute}`);
4564
};
4665

4766
/**
@@ -52,6 +71,7 @@ export function processNodes(filepath: string, content: string, ast: AST.Root):
5271
addDataAttribute(node);
5372
}
5473

74+
// Handle different node structures
5575
if (Array.isArray(node.children)) {
5676
node.children.forEach(walk);
5777
}

0 commit comments

Comments
 (0)