diff --git a/package-lock.json b/package-lock.json
index 434b6090..2413b311 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2089,7 +2089,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"aproba": {
"version": "1.2.0",
@@ -2110,12 +2111,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -2130,17 +2133,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -2257,7 +2263,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"ini": {
"version": "1.3.5",
@@ -2269,6 +2276,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -2283,6 +2291,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -2290,12 +2299,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@@ -2314,6 +2325,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -2394,7 +2406,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -2406,6 +2419,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"wrappy": "1"
}
@@ -2491,7 +2505,8 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"safer-buffer": {
"version": "2.1.2",
@@ -2527,6 +2542,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@@ -2546,6 +2562,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -2589,12 +2606,14 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
}
}
},
diff --git a/package.json b/package.json
index d8131a2d..1d340d22 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "svelte-preprocess",
- "version": "2.5.0",
+ "version": "2.5.1",
"license": "MIT",
"main": "src/index.js",
"types": "src/index.d.ts",
diff --git a/src/utils.js b/src/utils.js
index c258f0c6..967dad9a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -68,15 +68,15 @@ exports.addLanguageAlias = entries =>
entries.forEach(entry => LANG_DICT.set(...entry))
exports.getLanguage = (attributes, defaultLang) => {
- let lang
+ let lang = defaultLang
- if (attributes.src) {
+ if (attributes.lang) {
+ lang = attributes.lang
+ } else if (attributes.type) {
+ lang = attributes.type.replace(/^(text|application)\/(.*)$/, '$2')
+ } else if (attributes.src) {
lang = attributes.src.match(/\.([^/.]+)$/)
lang = lang ? lang[1] : defaultLang
- } else {
- lang = attributes.type
- ? attributes.type.replace(/^(text|application)\/(.*)$/, '$2')
- : attributes.lang || defaultLang
}
return {
diff --git a/test/fixtures/template.custom b/test/fixtures/template.custom
new file mode 100644
index 00000000..19102815
--- /dev/null
+++ b/test/fixtures/template.custom
@@ -0,0 +1 @@
+foo
\ No newline at end of file
diff --git a/test/index.test.js b/test/index.test.js
index 4533aff6..1afc7fbb 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -263,10 +263,11 @@ describe('detect - mimetype', () => {
{ type: 'application/ld+json', parser: 'ld+json' },
{ type: 'text/some-other', parser: 'some-other' },
{ lang: 'stylus', parser: 'stylus' },
+ { src: '../foo.custom', lang: 'customLanguage', parser: 'customLanguage' },
]
- MIMETYPES.forEach(({ type, lang, parser }) => {
- it(`should detect ${type || lang} as ${parser}`, async () => {
- expect(getLanguage({ type, lang }, 'javascript')).toEqual({
+ MIMETYPES.forEach(({ type, lang, src, parser }) => {
+ it(`should detect '${src || type || lang}' as '${parser}'`, async () => {
+ expect(getLanguage({ type, lang, src }, 'javascript')).toEqual({
lang: parser,
alias: parser,
})
@@ -330,17 +331,19 @@ describe('external files', () => {
describe('options', () => {
it('should accept custom method for a transformer', async () => {
- const input = ``
+ const input = `${getFixtureContent(
+ 'template.custom',
+ )}`
const opts = getPreprocess({
- pug: (content, filename) => {
- const code = require('pug').render(content, opts)
- return {
- code,
- }
+ transformers: {
+ customTransformer({ content, filename }) {
+ content = content.replace('foo', 'bar')
+ return { code: content, map: null }
+ },
},
})
const preprocessed = (await preprocess(input, opts)).trim()
- expect(preprocessed).toBe(parsedMarkup)
+ expect(preprocessed).toBe('bar')
})
it('should accept an options object as transformer value', async () => {