Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-loader

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-loader - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

test/fixtures/css.html

7

CHANGELOG.md
# svelte-loader changelog
## 1.1.0
* Add option to control CSS output (https://github.com/sveltejs/svelte-loader/pull/6)
* Add option to control output `format` and `name` (https://github.com/sveltejs/svelte-loader/pull/4)
* Fix parse/validation error context display (https://github.com/sveltejs/svelte-loader/pull/5)
## 1.0.1

@@ -4,0 +11,0 @@

3

example/package.json

@@ -18,3 +18,6 @@ {

"webpack": "^2.1.0-beta.27"
},
"dependencies": {
"svelte": "^1.1.3"
}
}

19

index.js
const { compile } = require('svelte');
const { parseQuery } = require('loader-utils');

@@ -7,16 +8,10 @@ module.exports = function(source, map) {

const filename = this.resourcePath;
const query = parseQuery(this.query);
try {
let { code, map } = compile(source, {
// name: CamelCase component name
filename: filename,
format: 'es',
onerror: (err) => {
console.log(err.message);
this.emitError(err.message);
},
onwarn: (warn) => {
console.log(warn.message);
this.emitWarn(warn.message);
}
format: query.format || 'es',
name: query.name,
css: query.css !== false,
});

@@ -26,4 +21,6 @@

} catch (err) {
this.callback(err);
// wrap error to provide correct
// context when logging to console
this.callback(new Error(err.toString()));
}
};
{
"name": "svelte-loader",
"version": "1.0.1",
"version": "1.1.0",
"author": "Nico Rehwaldt <git_nikku@nixis.de>",

@@ -21,6 +21,7 @@ "description": "A webpack loader for svelte",

"eslint-plugin-mocha": "^4.7.0",
"loader-utils": "^0.2.16",
"mocha": "^3.2.0",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
"svelte": "^1.0.7"
"svelte": "^1.2.0"
},

@@ -27,0 +28,0 @@ "peerDependencies": {

@@ -18,6 +18,8 @@ /* global describe, it */

function testLoader(fileName, callback) {
function testLoader(fileName, callback, query) {
return function() {
const fileContents = readFile(fileName);
const cacheableSpy = spy(function() { });

@@ -27,4 +29,2 @@

const fileContents = readFile(fileName);
loader.call({

@@ -34,2 +34,3 @@ cacheable: cacheableSpy,

filename: fileName,
query,
}, fileContents, null);

@@ -43,3 +44,3 @@

it('should compile good',
it('should compile',
testLoader('test/fixtures/good.html', function(err, code, map) {

@@ -54,38 +55,140 @@ expect(err).not.to.exist;

it('should compile bad',
testLoader('test/fixtures/bad.html', function(err, code, map) {
expect(err).to.exist;
describe('error handling', function() {
expect(code).not.to.exist;
expect(map).not.to.exist;
})
);
it('should handle parse error',
testLoader('test/fixtures/parse-error.html', function(err, code, map, context) {
expect(err).to.exist;
it('should compile with import / ES2015 features',
testLoader('test/fixtures/es2015.html', function(err, code, map) {
expect(err).not.to.exist;
expect(err.message).to.eql(
'Expected }}} (1:18)\n' +
'1: <p>Count: {{{count}}</p>\n' +
' ^\n' +
'2: <button on:click=\'set({ count: count + 1 })\'>+1</button>'
);
expect(code).to.exist;
expect(map).to.exist;
expect(code).not.to.exist;
expect(map).not.to.exist;
})
);
// es2015 statements remain
expect(code).to.contain('import { hello } from \'./utils\';');
expect(code).to.contain('data() {');
})
);
it('should handle wrong export',
testLoader('test/fixtures/export-error.html', function(err, code, map, context) {
it('should compile Component with with nesting',
testLoader('test/fixtures/parent.html', function(err, code, map) {
expect(err).not.to.exist;
expect(err).to.exist;
// es2015 statements remain
expect(code).to.contain('import Nested from \'./nested\';');
expect(err.message).to.eql(
'Unexpected token (5:7)\n' +
'3: <script>\n' +
'4: export {\n' +
'5: foo: \'BAR\'\n' +
' ^\n' +
'6: };\n' +
'7: </script>'
);
expect(code).to.exist;
expect(map).to.exist;
})
);
expect(code).not.to.exist;
expect(map).not.to.exist;
})
);
it('should validation error',
testLoader('test/fixtures/validation-error.html', function(err, code, map, context) {
expect(err).to.exist;
expect(err.message).to.eql(
'Computed properties can be function expressions or arrow function expressions (6:11)\n' +
'4: export default {\n' +
'5: computed: {\n' +
'6: foo: \'BAR\'\n' +
' ^\n' +
'7: }\n' +
'8: };'
);
expect(code).not.to.exist;
expect(map).not.to.exist;
})
);
});
describe('ES2015 features', function() {
it('should keep imports / methods',
testLoader('test/fixtures/es2015.html', function(err, code, map) {
expect(err).not.to.exist;
expect(code).to.exist;
expect(map).to.exist;
// es2015 statements remain
expect(code).to.contain('import { hello } from \'./utils\';');
expect(code).to.contain('data() {');
})
);
it('should keep nested Component import',
testLoader('test/fixtures/parent.html', function(err, code, map) {
expect(err).not.to.exist;
// es2015 statements remain
expect(code).to.contain('import Nested from \'./nested\';');
expect(code).to.exist;
expect(map).to.exist;
})
);
});
describe('configuration via query', function() {
describe('output + name', function() {
it('should configure CommonJS',
testLoader('test/fixtures/good.html', function(err, code, map) {
expect(err).not.to.exist;
expect(code).to.contain('module.exports = SvelteComponent;');
}, { format: 'cjs' })
);
it('should configure UMD + name',
testLoader('test/fixtures/good.html', function(err, code, map) {
expect(err).not.to.exist;
expect(code).to.contain('(global.FooComponent = factory());');
}, { format: 'umd', name: 'FooComponent' })
);
});
describe('css', function() {
it('should configure css (default)',
testLoader('test/fixtures/css.html', function(err, code, map) {
expect(err).not.to.exist;
expect(code).to.contain('if ( !addedCss ) addCss();');
})
);
it('should configure no css',
testLoader('test/fixtures/css.html', function(err, code, map) {
expect(err).not.to.exist;
expect(code).not.to.contain('if ( !addedCss ) addCss();');
}, { css: false })
);
});
});
});

@@ -96,2 +199,2 @@

return readFileSync(path, 'utf-8');
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc