Sorry, the diff of this file is not supported yet
+17
-0
@@ -57,2 +57,10 @@ /* | ||
| dest: 'tmp/angular_options_standard', | ||
| options: { | ||
| angular: { module: 'pegjs', factory: 'exampleParser' } | ||
| }, | ||
| foo: 'bar' | ||
| }, | ||
| angular_options_backcompat: { | ||
| src: 'test/fixtures/a.peg', | ||
| dest: 'tmp/angular_options_backcompat', | ||
| angular: { module: 'pegjs', factory: 'exampleParser' } | ||
@@ -64,2 +72,11 @@ }, | ||
| options: { exportVar: function(src){ return path.basename(src[0], '.peg'); } } | ||
| }, | ||
| wrapper_options: { | ||
| src: 'test/fixtures/a.peg', | ||
| dest: 'tmp/wrapper_options_standard', | ||
| options: { | ||
| wrapper: function (src, parser) { | ||
| return 'define(function () { return ' + parser + '; });'; | ||
| } | ||
| } | ||
| } | ||
@@ -66,0 +83,0 @@ }, |
+1
-1
| { | ||
| "name": "grunt-peg", | ||
| "description": "A grunt multi task that generates parsers from PEG grammars.", | ||
| "version": "1.4.0", | ||
| "version": "1.5.0", | ||
| "homepage": "https://github.com/dvberkel/grunt-peg", | ||
@@ -6,0 +6,0 @@ "author": { |
+27
-3
@@ -142,5 +142,7 @@ # grunt-peg | ||
| dest: "grammar/example.js", | ||
| angular: { | ||
| module: "pegjs", | ||
| factory: "exampleParser" | ||
| options: { | ||
| angular: { | ||
| module: "pegjs", | ||
| factory: "exampleParser" | ||
| } | ||
| } | ||
@@ -152,2 +154,24 @@ } | ||
| #### Custom Wrapper | ||
| It is also possible to wrap the generated parser in any code you | ||
| want. | ||
| ```js | ||
| grunt.initConfig({ | ||
| peg: { | ||
| options: { trackLineAndColumn: true }, | ||
| example : { | ||
| src: "grammar/example.peg", | ||
| dest: "grammar/example.js", | ||
| options: { | ||
| wrapper: function (src, parser) { | ||
| return 'define("example", [], function () { return ' + parser + '; });'; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| ``` | ||
| ##### Note on plugins | ||
@@ -154,0 +178,0 @@ |
+20
-17
@@ -26,2 +26,21 @@ /* | ||
| // backwards compatibility: | ||
| if (this.data.angular && !options.angular) { | ||
| options.angular = this.data.angular; | ||
| } | ||
| if (!options.wrapper) { | ||
| options.wrapper = function (src, parser) { | ||
| if (options.angular) { | ||
| return 'angular.module(\'' + options.angular.module + '\', []).factory(\'' + options.angular.factory + '\', function () { return ' + parser + '});'; | ||
| } else { | ||
| if (typeof options.exportVar === 'function') { | ||
| return options.exportVar(src) + ' = ' + parser + ';'; | ||
| } else { | ||
| return (typeof options.exportVar === 'string' ? options.exportVar : 'module.exports') + ' = ' + parser + ';'; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| // Iterate over all src-dest file pairs. | ||
@@ -66,20 +85,4 @@ files.forEach(function(f) { | ||
| 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. | ||
| if (f.angular != null){ | ||
| var angularModule = "angular.module('"+ f.angular.module+"', []).factory('"+ f.angular.factory+"',function(){ return "; | ||
| grunt.file.write(f.dest, angularModule + parser + '});'); | ||
| }else { | ||
| grunt.file.write(f.dest, exportVar(src) + ' = ' + parser + ';'); | ||
| } | ||
| grunt.file.write(f.dest, options.wrapper(src, parser)); | ||
@@ -86,0 +89,0 @@ grunt.log.writeln('Parser "' + f.dest + '" generated in ' + time + 'ms.'); |
+18
-0
@@ -79,2 +79,11 @@ /* | ||
| }, | ||
| angular_options_backcompat: function(test) { | ||
| test.expect(1); | ||
| var actual = grunt.file.read('tmp/angular_options_backcompat'); | ||
| var expected = grunt.file.read('test/expected/angular_options'); | ||
| test.equal(actual, expected, 'Unexpected parser generated for angular_options_backcompat'); | ||
| test.done(); | ||
| }, | ||
| exportVar_options: function(test) { | ||
@@ -88,3 +97,12 @@ test.expect(1); | ||
| test.done(); | ||
| }, | ||
| wrapper_options: function (test) { | ||
| test.expect(1); | ||
| var actual = grunt.file.read('tmp/wrapper_options_standard'); | ||
| var expected = grunt.file.read('test/expected/wrapper_options'); | ||
| test.equal(actual, expected, 'Unexpected parser generated for wrapper_options_standard'); | ||
| test.done(); | ||
| } | ||
| }; |
Sorry, the diff of this file is not supported yet
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
63707
14.59%18
5.88%257
14.73%242
11.01%