Skip to content

Commit

Permalink
Adapt to JS generated code exporting an object (not a function)
Browse files Browse the repository at this point in the history
See kaitai-io/kaitai_struct#1074

This is to adapt to the KSC changes from
kaitai-io/kaitai_struct_compiler#264.
  • Loading branch information
generalmimon committed Feb 16, 2024
1 parent a247c1f commit c78e102
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
16 changes: 8 additions & 8 deletions helpers/javascript/CustomFxNoArgs.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['kaitai-struct/KaitaiStream'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('kaitai-struct/KaitaiStream'));
define(['exports', 'kaitai-struct/KaitaiStream'], factory);
} else if (typeof exports === 'object' && exports !== null && typeof exports.nodeType !== 'number') {
factory(exports, require('kaitai-struct/KaitaiStream'));
} else {
root.CustomFxNoArgs = factory(root.KaitaiStream);
factory(root.CustomFxNoArgs || (root.CustomFxNoArgs = {}), root.KaitaiStream);
}
}(this, function (KaitaiStream) {
})(typeof self !== 'undefined' ? self : this, function (CustomFxNoArgs_, KaitaiStream) {
var CustomFxNoArgs = (function() {
function CustomFxNoArgs() {
}
Expand All @@ -25,5 +25,5 @@ var CustomFxNoArgs = (function() {

return CustomFxNoArgs;
})();
return CustomFxNoArgs;
}));
CustomFxNoArgs_.CustomFxNoArgs = CustomFxNoArgs;
});
18 changes: 9 additions & 9 deletions helpers/javascript/MyCustomFx.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['kaitai-struct/KaitaiStream'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('kaitai-struct/KaitaiStream'));
define(['exports', 'kaitai-struct/KaitaiStream'], factory);
} else if (typeof exports === 'object' && exports !== null && typeof exports.nodeType !== 'number') {
factory(exports, require('kaitai-struct/KaitaiStream'));
} else {
root.MyCustomFx = factory(root.KaitaiStream);
factory(root.MyCustomFx || (root.MyCustomFx = {}), root.KaitaiStream);
}
}(this, function (KaitaiStream) {
})(typeof self !== 'undefined' ? self : this, function (MyCustomFx_, KaitaiStream) {
var MyCustomFx = (function() {
function MyCustomFx(key, flag, someBytes) {
this.key = flag ? key : -key;
Expand All @@ -18,11 +18,11 @@ var MyCustomFx = (function() {
var dest = new Uint8Array(len);
for (var i = 0; i < len; i++) {
dest[i] = src[i] + this.key;
}
}
return dest;
}

return MyCustomFx;
})();
return MyCustomFx;
}));
MyCustomFx_.MyCustomFx = MyCustomFx;
});
16 changes: 8 additions & 8 deletions helpers/javascript/nested-deeply/CustomFx.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['kaitai-struct/KaitaiStream'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('kaitai-struct/KaitaiStream'));
define(['exports', 'kaitai-struct/KaitaiStream'], factory);
} else if (typeof exports === 'object' && exports !== null && typeof exports.nodeType !== 'number') {
factory(exports, require('kaitai-struct/KaitaiStream'));
} else {
root.CustomFx = factory(root.KaitaiStream);
factory(root.CustomFx || (root.CustomFx = {}), root.KaitaiStream);
}
}(this, function (KaitaiStream) {
})(typeof self !== 'undefined' ? self : this, function (CustomFx_, KaitaiStream) {
var CustomFx = (function() {
function CustomFx(key) {
this.key = key;
Expand All @@ -26,5 +26,5 @@ var CustomFx = (function() {

return CustomFx;
})();
return CustomFx;
}));
CustomFx_.CustomFx = CustomFx;
});
2 changes: 1 addition & 1 deletion helpers/javascript/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function testHelper(className, fileName, testFunc) {

describe(className, function() {
it('parses test properly', function(done) {
var parser = require(className);
var parser = require(className)[className];
fs.readFile(fileName, function(err, buf) {
if (err) {
done(err);
Expand Down
2 changes: 1 addition & 1 deletion helpers/javascript/testHelperStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function testHelperStream(className, fileName, testFunc) {

describe(className, function() {
it('parses test properly', function(done) {
var parser = require(className);
var parser = require(className)[className];
fs.readFile(fileName, function(err, buf) {
var st = new KaitaiStream(buf);
testFunc(st, parser);
Expand Down
2 changes: 1 addition & 1 deletion helpers/javascript/testHelperThrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function testHelperThrows(className, fileName, excClass) {
describe(className, function() {
it('parses test properly', function(done) {
assert.ok(excClass);
var parser = require(className);
var parser = require(className)[className];
fs.readFile(fileName, function(err, buf) {
var st = new KaitaiStream(buf);
assert.throws(
Expand Down

0 comments on commit c78e102

Please sign in to comment.