Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

grunt-peg

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-peg - npm Package Compare versions

Comparing version
1.4.0
to
1.5.0
test/expected/wrapper_options

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": {

@@ -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 @@

@@ -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.');

@@ -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