Skip to content

fix: deprecate type attribute #417

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

Merged
merged 3 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ The following options can be passed to the preprocessor. None are required:
| Option | Default | Description |
| --------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `markupTagName` | `"template"` | `string` that sets the name of the tag `svelte-preprocess` looks for markup in custom languages.<br><br>i.e `markup` makes it possible to write your markup between `<markup lang="..."></markup>` tag. |
| `aliases` | `null` | A list of tuples `[alias: string, language: string]` that correlates an `alias` to a `language`<br><br>i.e `['cst', 'customLanguage']` means<br>`<... src="./file.cst">`<br>`<... lang="cst">`<br>`<... type="text/customLanguage">`<br>`<... type="application/customLanguage">`<br>are treated as `customLanguage`. |
| preserve | `[]` | A `string` list of languages/aliases that shouldn't pass through the preprocessor. (i.e `ld+json`) |
| `aliases` | `null` | A list of tuples `[alias: string, language: string]` that correlates an `alias` to a `language`<br><br>i.e `['cst', 'customLanguage']` means<br>`<... src="./file.cst">`<br>`<... lang="cst">`<br>are treated as `customLanguage`. |
| `preserve` | `[]` | A `string` list of languages/aliases that shouldn't pass through the preprocessor. (i.e `ld+json`) |
| `sourceMap` | `false` | If `true`, `svelte-preprocess` generates sourcemap for every language that supports it. |

##### Configuring preprocessors
Expand Down Expand Up @@ -133,7 +133,7 @@ export default {
};
```

Now `svelte-preprocess` will use the `potatoLanguage` preprocessor whenever it finds a tag with `lang="potato"`, `type="text/potatoLanguage"` or `src="./index.pot"`.
Now `svelte-preprocess` will use the `potatoLanguage` preprocessor whenever it finds a tag with `lang="potato"` or `src="./index.pot"`.

These methods receive the same arguments and act exactly like a [common svelte preprocessor](https://svelte.dev/docs#svelte_preprocess), but the concept of `markup`/`style`/`script` is abstracted as they are executed whenever `svelte-preprocess` find the aforementioned attributes.

Expand Down Expand Up @@ -273,7 +273,7 @@ The PostCSS preprocessor accepts four options:

In auto-preprocessing mode, you can set `postcss: true` if `postcss-load-config` is installed and `svelte-preprocess` will look for a PostCSS config file in your project.

When a `lang="sugarss"`/`type="text/sugarss"` is found, `sugarss` is automatically loaded and extra indentation is removed.
When a `lang="sugarss"` is found, `sugarss` is automatically loaded and extra indentation is removed.

You can check the [PostCSS API reference](https://api.postcss.org/) for PostCSS specific options.

Expand Down Expand Up @@ -356,7 +356,7 @@ You can check the [Sass API reference](https://sass-lang.com/documentation/js-ap

Note: `svelte-preprocess` automatically configures inclusion paths for your root directory, `node_modules` and for the current file's directory.

Note: when a `lang="sass"`/`type="text/sass"` is found, `indentedSyntax` is automatically set to `true`.
Note: when a `lang="sass"` is found, `indentedSyntax` is automatically set to `true`.

Note: `sass`, with indented syntax, and `scss` are not interchangeable so make sure to configure the correct one that fits your needs.

Expand Down
2 changes: 1 addition & 1 deletion examples/sapper-rollup/src/routes/blog/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
</script>

<script type="text/typescript">
<script lang="ts">
interface Post {
title: string
slug: string
Expand Down
6 changes: 3 additions & 3 deletions examples/svelte-rollup/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<template type="text/pug">
<template lang="pug">
h1 Hello!
br
input(bind:value="{label}")
br
Nested("{label}")
</template>

<script type="text/typescript">
<script lang="ts">
import Nested from './Nested.svelte'
export let label: string = ''

$: console.log(label)
</script>

<style type="text/stylus">
<style lang="stylus">
h1
color blue
</style>
12 changes: 12 additions & 0 deletions src/modules/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,25 @@ export const getLanguage = (attributes: PreprocessorArgs['attributes']) => {
}

alias = attributes.lang;

if (alias === 'typescript') {
console.warn(
`[svelte-preprocess] Deprecation notice: using 'lang="typescript"' is no longer recommended and will be removed in the next major version. Please use 'lang="ts"' instead.`,
);
}
} else if (attributes.type) {
// istanbul ignore if
if (typeof attributes.type !== 'string') {
throw new Error('type attribute must be string');
}

alias = attributes.type.replace(/^(text|application)\/(.*)$/, '$2');

if (attributes.type.includes('text/')) {
console.warn(
`[svelte-preprocess] Deprecation notice: using the "type" attribute is no longer recommended and will be removed in the next major version. Please use the "lang" attribute instead.`,
);
}
} else if (
typeof attributes.src === 'string' &&
isValidLocalPath(attributes.src)
Expand Down
2 changes: 1 addition & 1 deletion test/transformers/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const autoProcessTS = (content: string, compilerOptions?: any) => {
return opts.script?.({
content,
markup: `<script lang="ts">${content}</script>`,
attributes: { type: 'text/typescript' },
attributes: { lang: 'ts' },
filename: resolve(__dirname, '..', 'App.svelte'),
}) as Processed & { diagnostics: Diagnostic[] };
};
Expand Down