Skip to content

Commit

Permalink
Fixes #3533 (#3544)
Browse files Browse the repository at this point in the history
* Fixes #3533
  • Loading branch information
matthew-dean authored Jul 16, 2020
1 parent e188f44 commit b93a085
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/less/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ module.exports = function(grunt) {
// Handle async / await in Rollup build for tests
// Remove this when Node 6 is no longer supported for the build/test process
const nodeVersion = semver.major(process.versions.node);
const tsNodeRuntime = path.resolve(path.join('node_modules', '.bin', 'ts-node'));
let scriptRuntime = 'node';
if (nodeVersion < 8) {
scriptRuntime = path.resolve(path.join('node_modules', '.bin', 'ts-node'));
scriptRuntime = tsNodeRuntime;
}

// Project configuration.
Expand Down Expand Up @@ -228,7 +229,10 @@ module.exports = function(grunt) {
command: scriptRuntime + " build/rollup.js --browser --out=./tmp/browser/less.min.js"
},
test: {
command: "node test/index.js"
command: [
tsNodeRuntime + " test/test-es6.ts",
"node test/index.js"
].join(' && ')
},
generatebrowser: {
command: 'node test/browser/generator/generate.js'
Expand Down
9 changes: 9 additions & 0 deletions packages/less/src/less/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,14 @@ export default (environment, fileManagers) => {
}
}

/**
* Some of the functions assume a `this` context of the API object,
* which causes it to fail when wrapped for ES6 imports.
*
* An assumed `this` should be removed in the future.
*/
initial.parse = initial.parse.bind(api);
initial.render = initial.render.bind(api);

return api;
};
17 changes: 17 additions & 0 deletions packages/less/test/test-es6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://github.com/less/less.js/issues/3533
console.log('Testing ES6 imports...')

import less from '..';
let lessRender = less.render;

// then I call lessRender on something
let y = lessRender(`
body {
a: 1;
b: 2;
c: 30;
d: 4;
}`, {sourceMap: {}}, function(error, output) {
if (error)
console.error(error)
})

0 comments on commit b93a085

Please sign in to comment.