Sorry, the diff of this file is not supported yet
+8
-1
@@ -11,2 +11,4 @@ /* | ||
| var path = require('path'); | ||
| module.exports = function(grunt) { | ||
@@ -56,3 +58,8 @@ | ||
| dest: 'tmp/angular_options_standard', | ||
| angular: { module: 'pegjs', factory: 'exampleParser' } | ||
| angular: { module: 'pegjs', factory: 'exampleParser' } | ||
| }, | ||
| exportVar_options: { | ||
| src: 'test/fixtures/a.peg', | ||
| dest: 'tmp/exportVar_options_standard', | ||
| options: { exportVar: function(src){ return path.basename(src[0], '.peg'); } } | ||
| } | ||
@@ -59,0 +66,0 @@ }, |
+1
-1
| { | ||
| "name": "grunt-peg", | ||
| "description": "A grunt multi task that generates parsers from PEG grammars.", | ||
| "version": "1.3.1", | ||
| "version": "1.4.0", | ||
| "homepage": "https://github.com/dvberkel/grunt-peg", | ||
@@ -6,0 +6,0 @@ "author": { |
+26
-2
@@ -40,3 +40,3 @@ # grunt-peg | ||
| #### exportVar | ||
| Type: `String` | ||
| Type: `String` | `function` | ||
| Default value: 'module.exports' | ||
@@ -46,2 +46,6 @@ | ||
| If the `exportVar` is of type `function`, the function needs to return | ||
| the variable as a `String`. The function gets passed the `src` | ||
| variable to base the variable off. | ||
| ### Usage Examples | ||
@@ -85,2 +89,21 @@ | ||
| #### Dynamic `exportVar` | ||
| In this example a [PEG][] grammar as described in the file | ||
| `grammar/example.peg` is used to generate parser | ||
| `grammar/example.js`, the export variable being defined via a function | ||
| and will result in `example`. | ||
| ```js | ||
| grunt.initConfig({ | ||
| peg: { | ||
| example : { | ||
| src: "grammar/example.peg", | ||
| dest: "grammar/example.js", | ||
| options: { exportVar: function(src){ return path.basename(src[0], '.peg'); } } | ||
| } | ||
| } | ||
| }) | ||
| ``` | ||
| #### Passing Options to PEG | ||
@@ -173,3 +196,4 @@ | ||
| * 2014-03-20 v1.3.1 Add license headers to all source files | ||
| * 2014-06-09 v1.4.0 Dynamic `exportVar` | ||
| * 2014-05-15 v1.3.1 Add license headers to all source files | ||
| * 2014-03-20 v1.3.0 Wrap in Angular Factory | ||
@@ -176,0 +200,0 @@ * 2014-01-05 v1.2.0 Support plugins |
+12
-2
@@ -65,2 +65,13 @@ /* | ||
| var exportVar = function(src){ | ||
| if (typeof options.exportVar === 'string') { | ||
| return options.exportVar; | ||
| } | ||
| if (typeof options.exportVar === 'function') { | ||
| return options.exportVar(src); | ||
| } | ||
| grunt.log.warn('Unkown type \'' + (typeof options.exportVar) + '\' for exportVar, picking default'); | ||
| return 'module.exports'; | ||
| } | ||
| // Save the parser. | ||
@@ -71,6 +82,5 @@ if (f.angular != null){ | ||
| }else { | ||
| grunt.file.write(f.dest, options.exportVar + ' = ' + parser + ';'); | ||
| grunt.file.write(f.dest, exportVar(src) + ' = ' + parser + ';'); | ||
| } | ||
| grunt.log.writeln('Parser "' + f.dest + '" generated in ' + time + 'ms.'); | ||
@@ -77,0 +87,0 @@ }); |
+9
-0
@@ -78,3 +78,12 @@ /* | ||
| test.done(); | ||
| }, | ||
| exportVar_options: function(test) { | ||
| test.expect(1); | ||
| var actual = grunt.file.read('tmp/exportVar_options_standard'); | ||
| var expected = grunt.file.read('test/expected/exportVar_options'); | ||
| test.equal(actual, expected, 'Unexpected parser generated for exportVar_options_standard'); | ||
| test.done(); | ||
| } | ||
| }; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
55595
16.84%17
6.25%224
11.44%218
12.37%