Skip to content

Commit

Permalink
fix: RollupJS reexports detection (#59)
Browse files Browse the repository at this point in the history
* fix: RollupJS reexports detection

* ensure js consistency
  • Loading branch information
guybedford authored Jul 15, 2021
1 parent 466b1a2 commit 32cfbbf
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 90 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
(`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)?
)?
) |
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER$1 `, ` IDENTIFIER$2 `)` | IDENTIFIER$1 `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` | IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
)
(
EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? |
Expand Down
8 changes: 5 additions & 3 deletions lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,10 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch !== 33/*!*/) break;
pos += 1;
ch = commentWhitespace();
if (source.startsWith(id, pos)) {
pos += id.length;
if (ch === 79/*O*/ && source.startsWith('bject', pos + 1) && source[pos + 6] === '.') {
if (!tryParseObjectHasOwnProperty(it_id)) break;
}
else if (identifier()) {
ch = commentWhitespace();
if (ch !== 46/*.*/) break;
pos++;
Expand All @@ -669,7 +671,7 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch !== 41/*)*/) break;
pos += 1;
}
else if (!tryParseObjectHasOwnProperty(it_id)) break;
else break;
ch = commentWhitespace();
}
if (ch !== 41/*)*/) break;
Expand Down
Binary file modified lib/lexer.wasm
Binary file not shown.
170 changes: 88 additions & 82 deletions lib/lexer.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2879,107 +2879,113 @@
i32.const 2
i32.add
i32.store offset=20540
call 39
drop
block ;; label = @6
block ;; label = @7
i32.const 0
i32.load offset=20540
local.tee 0
local.get 2
local.get 6
call 65
br_if 0 (;@7;)
i32.const 0
local.get 0
local.get 7
i32.const 1
i32.shl
i32.add
i32.store offset=20540
call 39
i32.const 46
i32.ne
br_if 6 (;@1;)
i32.const 0
i32.const 0
i32.load offset=20540
i32.const 2
i32.add
i32.store offset=20540
call 39
i32.const 104
local.tee 0
i32.const 79
i32.ne
br_if 6 (;@1;)
br_if 0 (;@7;)
i32.const 0
i32.load offset=20540
local.tee 0
i32.const 2
i32.add
i32.const 97
i32.const 115
i32.const 79
i32.const 119
i32.const 110
i32.const 80
i32.const 114
i32.const 111
i32.const 112
i32.const 98
i32.const 106
i32.const 101
i32.const 114
i32.const 99
i32.const 116
i32.const 121
call 47
i32.const 46
call 38
i32.eqz
br_if 6 (;@1;)
i32.const 0
local.get 0
i32.const 28
i32.add
i32.store offset=20540
call 39
i32.const 40
i32.ne
br_if 6 (;@1;)
i32.const 0
i32.const 0
i32.load offset=20540
i32.const 2
i32.add
i32.store offset=20540
call 39
drop
i32.const 0
i32.load offset=20540
local.tee 0
br_if 0 (;@7;)
local.get 4
local.get 3
call 65
br_if 6 (;@1;)
i32.const 0
local.get 0
local.get 8
i32.const 1
i32.shl
i32.add
i32.store offset=20540
call 39
i32.const 41
i32.ne
call 51
i32.eqz
br_if 6 (;@1;)
i32.const 0
i32.const 0
i32.load offset=20540
i32.const 2
i32.add
i32.store offset=20540
br 1 (;@6;)
end
local.get 0
call 45
i32.eqz
br_if 0 (;@6;)
call 39
i32.const 46
i32.ne
br_if 5 (;@1;)
i32.const 0
i32.const 0
i32.load offset=20540
i32.const 2
i32.add
i32.store offset=20540
call 39
i32.const 104
i32.ne
br_if 5 (;@1;)
i32.const 0
i32.load offset=20540
local.tee 0
i32.const 2
i32.add
i32.const 97
i32.const 115
i32.const 79
i32.const 119
i32.const 110
i32.const 80
i32.const 114
i32.const 111
i32.const 112
i32.const 101
i32.const 114
i32.const 116
i32.const 121
call 47
i32.eqz
br_if 5 (;@1;)
i32.const 0
local.get 0
i32.const 28
i32.add
i32.store offset=20540
call 39
i32.const 40
i32.ne
br_if 5 (;@1;)
i32.const 0
i32.const 0
i32.load offset=20540
i32.const 2
i32.add
i32.store offset=20540
call 39
drop
i32.const 0
i32.load offset=20540
local.tee 0
local.get 4
local.get 3
call 65
br_if 5 (;@1;)
i32.const 0
local.get 0
local.get 8
call 51
i32.eqz
i32.const 1
i32.shl
i32.add
i32.store offset=20540
call 39
i32.const 41
i32.ne
br_if 5 (;@1;)
i32.const 0
i32.const 0
i32.load offset=20540
i32.const 2
i32.add
i32.store offset=20540
end
call 39
local.set 0
Expand Down
7 changes: 4 additions & 3 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,10 @@ void tryParseObjectDefineOrKeys (bool keys) {
if (ch != '!') break;
pos += 1;
ch = commentWhitespace();
if (memcmp(pos, id_start, id_len * sizeof(uint16_t)) == 0) {
pos += id_len;
if (ch == 'O' && str_eq6(pos + 1, 'b', 'j', 'e', 'c', 't', '.')) {
if (!tryParseObjectHasOwnProperty(it_id_start, it_id_len)) break;
}
else if (identifier(ch)) {
ch = commentWhitespace();
if (ch != '.') break;
pos++;
Expand All @@ -659,7 +661,6 @@ void tryParseObjectDefineOrKeys (bool keys) {
if (ch != ')') break;
pos += 1;
}
else if (!tryParseObjectHasOwnProperty(it_id_start, it_id_len)) break;
ch = commentWhitespace();
}
if (ch != ')') break;
Expand Down
7 changes: 6 additions & 1 deletion test/_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,13 @@ suite('Lexer', () => {
if (k !== 'default' && !Object.hasOwnProperty.call(exports, k)) exports[k] = external5[k];
});
const not = require('not');
Object.keys(not).forEach(function (k) {
if (k !== 'default' && !a().hasOwnProperty(k)) exports[k] = not[k];
});
Object.keys(external6).forEach(function (k) {
if (k !== 'default' && !external6.hasOwnProperty(k)) exports[k] = external6[k];
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = external6[k];
});
const external𤭢 = require('external𤭢');
Expand Down

0 comments on commit 32cfbbf

Please sign in to comment.