Skip to content

Commit b93a085

Browse files
authored
Fixes #3533 (#3544)
* Fixes #3533
1 parent e188f44 commit b93a085

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

packages/less/Gruntfile.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ module.exports = function(grunt) {
190190
// Handle async / await in Rollup build for tests
191191
// Remove this when Node 6 is no longer supported for the build/test process
192192
const nodeVersion = semver.major(process.versions.node);
193+
const tsNodeRuntime = path.resolve(path.join('node_modules', '.bin', 'ts-node'));
193194
let scriptRuntime = 'node';
194195
if (nodeVersion < 8) {
195-
scriptRuntime = path.resolve(path.join('node_modules', '.bin', 'ts-node'));
196+
scriptRuntime = tsNodeRuntime;
196197
}
197198

198199
// Project configuration.
@@ -228,7 +229,10 @@ module.exports = function(grunt) {
228229
command: scriptRuntime + " build/rollup.js --browser --out=./tmp/browser/less.min.js"
229230
},
230231
test: {
231-
command: "node test/index.js"
232+
command: [
233+
tsNodeRuntime + " test/test-es6.ts",
234+
"node test/index.js"
235+
].join(' && ')
232236
},
233237
generatebrowser: {
234238
command: 'node test/browser/generator/generate.js'

packages/less/src/less/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,14 @@ export default (environment, fileManagers) => {
8888
}
8989
}
9090

91+
/**
92+
* Some of the functions assume a `this` context of the API object,
93+
* which causes it to fail when wrapped for ES6 imports.
94+
*
95+
* An assumed `this` should be removed in the future.
96+
*/
97+
initial.parse = initial.parse.bind(api);
98+
initial.render = initial.render.bind(api);
99+
91100
return api;
92101
};

packages/less/test/test-es6.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// https://github.com/less/less.js/issues/3533
2+
console.log('Testing ES6 imports...')
3+
4+
import less from '..';
5+
let lessRender = less.render;
6+
7+
// then I call lessRender on something
8+
let y = lessRender(`
9+
body {
10+
a: 1;
11+
b: 2;
12+
c: 30;
13+
d: 4;
14+
}`, {sourceMap: {}}, function(error, output) {
15+
if (error)
16+
console.error(error)
17+
})

0 commit comments

Comments
 (0)