Browse Source

Merge pull request #1395 from svaarala/fix-module-loader-last-line

Allow modules with // on last unterminated line
pull/1400/head
Sami Vaarala 8 years ago
committed by GitHub
parent
commit
79dd8bc7de
  1. 3
      RELEASES.rst
  2. 1
      extras/module-duktape/Makefile
  3. 2
      extras/module-duktape/duk_module_duktape.c
  4. 1
      extras/module-node/Makefile
  5. 2
      extras/module-node/duk_module_node.c
  6. 2
      extras/module-node/test.c

3
RELEASES.rst

@ -2522,6 +2522,9 @@ Planned
* Fix duk_error_raw() compile warning with -Wmissing-prototypes (GH-1390)
* Fix module-duktape and module-node handling of a module source which has
a // comment on the last line without a trailing newline (GH-1394, GH-1395)
* Avoid log2(), log10(), cbrt(), and trunc() on Android (GH-1325, GH-1341)
* Portability improvements for Solaris, HPUX, and AIX (GH-1356)

1
extras/module-duktape/Makefile

@ -11,3 +11,4 @@ test:
./test 'assert(typeof Duktape.modSearch === "undefined");'
./test 'Duktape.modSearch = function myModSearch(id) { return "exports.foo = 123;" }; assert(require("dummy").foo === 123);'
./test 'Duktape.modSearch = function myModSearch(id) { return "exports.foo = 234;" }; delete Duktape; assert(typeof Duktape === "undefined"); assert(require("dummy").foo === 234);'
./test 'Duktape.modSearch = function myModSearch(id) { return "exports.foo = 234; // comment" }; delete Duktape; assert(typeof Duktape === "undefined"); assert(require("dummy").foo === 234);'

2
extras/module-duktape/duk_module_duktape.c

@ -346,7 +346,7 @@ static duk_ret_t duk__require(duk_context *ctx) {
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
*/
duk_push_string(ctx, "})");
duk_push_string(ctx, "\n})"); /* Newline allows module last line to contain a // comment. */
duk_concat(ctx, 3);
if (!duk_get_prop_string(ctx, DUK__IDX_MODULE, "filename")) {
/* module.filename for .fileName, default to resolved ID if

1
extras/module-node/Makefile

@ -15,3 +15,4 @@ test:
./test 'var ape = require("ape"); assert(ape.module.loaded === true && ape.wasLoaded === false, "module.loaded");'
./test 'var ape = require("ape"); assert(ape.__filename === "ape.js", "__filename");'
./test 'var badger = require("badger"); assert(badger.foo === 123 && badger.bar === 234, "exports.foo assignment");'
./test 'var comment = require("comment"); assert(comment.foo === 123 && comment.bar === 234, "last line with // comment");'

2
extras/module-node/duk_module_node.c

@ -218,7 +218,7 @@ static duk_int_t duk__eval_module_source(duk_context *ctx) {
*/
duk_push_string(ctx, "(function(exports,require,module,__filename,__dirname){");
duk_dup(ctx, -2); /* source */
duk_push_string(ctx, "})");
duk_push_string(ctx, "\n})"); /* Newline allows module last line to contain a // comment. */
duk_concat(ctx, 3);
/* [ ... module source func_src ] */

2
extras/module-node/test.c

@ -36,6 +36,8 @@ static duk_ret_t cb_load_module(duk_context *ctx) {
duk_push_string(ctx, "module.exports = { module: module, __filename: __filename, wasLoaded: module.loaded };");
} else if (strcmp(module_id, "badger.js") == 0) {
duk_push_string(ctx, "exports.foo = 123; exports.bar = 234;");
} else if (strcmp(module_id, "comment.js") == 0) {
duk_push_string(ctx, "exports.foo = 123; exports.bar = 234; // comment");
} else {
duk_error(ctx, DUK_ERR_TYPE_ERROR, "cannot find module: %s", module_id);
}

Loading…
Cancel
Save