-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from EMH333/preprocess-warning-location
Correctly provide file locations for errors and warnings when using preprocessors
- Loading branch information
Showing
12 changed files
with
229 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,5 +49,8 @@ | |
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"dependencies": { | ||
"@jridgewell/trace-mapping": "^0.3.18" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { test } from "uvu"; | ||
import * as assert from "uvu/assert"; | ||
import { build as _build } from "esbuild"; | ||
import { typescript } from "svelte-preprocess-esbuild"; | ||
import sveltePlugin from "../dist/index.mjs"; | ||
|
||
test("Errors (with preprocessors) are in the right spot", async () => { | ||
try { | ||
await _build({ | ||
entryPoints: ["./test/fixtures/errors/entry.js"], | ||
outdir: "../example/dist", | ||
bundle: true, | ||
write: false, //Don't write anywhere | ||
sourcemap: true, | ||
plugins: [ | ||
sveltePlugin({ | ||
preprocess: [typescript()], | ||
compilerOptions: { dev: true }, | ||
}), | ||
], | ||
logLevel: "silent", | ||
}); | ||
} catch (e) { | ||
assert.equal(e.errors.length, 1, "Should have one error"); | ||
assert.equal(e.warnings.length, 0, "Should not have warnings"); | ||
|
||
const error = e.errors[0]; | ||
|
||
assert.equal( | ||
error.location.file, | ||
"test/fixtures/errors/error.svelte", | ||
"Should have the right file", | ||
); | ||
assert.equal(error.location.line, 12, "Should have the right line"); | ||
assert.equal(error.location.column, 31, "Should have the right column"); | ||
assert.equal( | ||
error.text, | ||
"Expected value for the attribute", | ||
"Should have the right error message", | ||
); | ||
return; | ||
} | ||
|
||
assert.unreachable("Should have thrown an error"); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Test from "./error.svelte"; | ||
|
||
new Test({ | ||
target: document.body, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script lang="ts"> | ||
interface Test { | ||
yellThisThing: String; | ||
} | ||
// some sort of javascript error | ||
function event() { | ||
console.log({ yellThisThing: "something" } as Test); | ||
} | ||
</script> | ||
|
||
<button on:click={event} class=>Yell "something"</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { typescript } = require("svelte-preprocess-esbuild"); | ||
const { sass } = require("svelte-preprocess-sass"); | ||
|
||
module.exports = { | ||
preprocess: [{ style: sass() }, typescript()], | ||
}; |
50 changes: 26 additions & 24 deletions
50
test/fixtures/preprocessing-sourcemaps/pp-sourcemaps.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
<script lang="typescript"> | ||
interface Test { | ||
yellThisThing: String; | ||
} | ||
interface Test { | ||
yellThisThing: String; | ||
} | ||
function event() { | ||
tryThisThing({ yellThisThing: "something!" }); | ||
change(); | ||
} | ||
function event() { | ||
tryThisThing({ yellThisThing: "something!" }); | ||
change(); | ||
} | ||
function tryThisThing(input: Test) { | ||
console.log(input.yellThisThing.toUpperCase()); | ||
} | ||
function tryThisThing(input: Test) { | ||
console.log(input.yellThisThing.toUpperCase()); | ||
} | ||
let inputBinding: HTMLInputElement; | ||
let inputBinding: HTMLInputElement; | ||
function change() { | ||
inputBinding.value = "testing" + Math.round(Math.random() * 100); | ||
} | ||
function change() { | ||
inputBinding.value = "testing" + Math.round(Math.random() * 100); | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
@use "sourcemapImport.scss"; | ||
@use "sass:color"; | ||
.sourcemap { | ||
$primary-color: #6b717f; | ||
color: $primary-color; | ||
border: 1px solid color.scale($primary-color, $lightness: 20%); | ||
} | ||
</style> | ||
|
||
<button on:click={event} class="sourcemap">Yell "something"</button> | ||
<input type="text" name="testingInput" bind:this={inputBinding} /> | ||
|
||
<img src="foo.jpg" /> | ||
|
||
<style lang="scss"> | ||
@use "sourcemapImport.scss"; | ||
@use "sass:color"; | ||
.sourcemap { | ||
$primary-color: #6b717f; | ||
color: $primary-color; | ||
border: 1px solid color.scale($primary-color, $lightness: 20%); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { typescript } = require("svelte-preprocess-esbuild"); | ||
const { sass } = require("svelte-preprocess-sass"); | ||
|
||
module.exports = { | ||
preprocess: [{ style: sass() }, typescript()], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.