Skip to content
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

add inline js options and upgrade less version #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test.watch": "jest --watch"
},
"dependencies": {
"less": "^3.9.0"
"less": "^3.10.0"
},
"peerDependencies": {
"@stencil/core": "^1.0.2"
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ exports.config = {

Note that each of these files are always added to each component, so in most cases they shouldn't contain CSS because it'll get duplicated in each component. Instead, `injectGlobalPaths` should only be used for Less variables, mixins and functions, but not contain any CSS.

### Enable Inline JavaScript

False by default starting in Less.js v3.0.0. Enables evaluation of JavaScript inline in .less files. This created a security problem for some developers who didn't expect user input for style sheets to have executable code.

```js
exports.config = {
plugins: [
less({
javascriptEnabled: true
})
]
};
```



## Related

* [Less](https://www.npmjs.com/package/less)
Expand Down
1 change: 1 addition & 0 deletions src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from '@stencil/core/internal';
export interface PluginOptions {
plugins?: Less.Plugin[];
injectGlobalPaths?: string[];
javascriptEnabled?: boolean;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function less(opts: d.PluginOptions = {}): d.Plugin {

render(renderOpts.data, {
plugins: renderOpts.plugins,
javascriptEnabled: renderOpts.javascriptEnabled,
filename: fileName
}, (err: any, lessResult: any) => {
if (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function usePlugin(fileName: string) {
}


export function getRenderOptions(opts: d.PluginOptions, sourceText: string, context: d.PluginCtx): { data: string; plugins: Less.Plugin[] } {
export function getRenderOptions(opts: d.PluginOptions, sourceText: string, context: d.PluginCtx): { data: string; javascriptEnabled: boolean; plugins: Less.Plugin[] } {
const injectGlobalPaths = Array.isArray(opts.injectGlobalPaths) ? opts.injectGlobalPaths.slice() : [];

let injectText = '';
Expand All @@ -26,6 +26,7 @@ export function getRenderOptions(opts: d.PluginOptions, sourceText: string, cont

return {
data: `${injectText}${sourceText}`,
javascriptEnabled: opts.javascriptEnabled || false,
plugins: opts.plugins || []
};
}
Expand Down
7 changes: 7 additions & 0 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ describe('getRenderOptions', () => {
expect(output.data).toBe(sourceText);
});

it('should enabled inline javaScript', ()=>{
const input: d.PluginOptions = {
javascriptEnabled: true
};
const output = util.getRenderOptions(input, sourceText,context);
expect(output.javascriptEnabled).toBe(true);
})
});


Expand Down