Skip to content

Commit 32cfbbf

Browse files
authored
fix: RollupJS reexports detection (#59)
* fix: RollupJS reexports detection * ensure js consistency
1 parent 466b1a2 commit 32cfbbf

File tree

6 files changed

+104
-90
lines changed

6 files changed

+104
-90
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
113113
(`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)?
114114
)?
115115
) |
116-
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER$1 `, ` IDENTIFIER$2 `)` | IDENTIFIER$1 `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
116+
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` | IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
117117
)
118118
(
119119
EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? |

lexer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,10 @@ function tryParseObjectDefineOrKeys (keys) {
651651
if (ch !== 33/*!*/) break;
652652
pos += 1;
653653
ch = commentWhitespace();
654-
if (source.startsWith(id, pos)) {
655-
pos += id.length;
654+
if (ch === 79/*O*/ && source.startsWith('bject', pos + 1) && source[pos + 6] === '.') {
655+
if (!tryParseObjectHasOwnProperty(it_id)) break;
656+
}
657+
else if (identifier()) {
656658
ch = commentWhitespace();
657659
if (ch !== 46/*.*/) break;
658660
pos++;
@@ -669,7 +671,7 @@ function tryParseObjectDefineOrKeys (keys) {
669671
if (ch !== 41/*)*/) break;
670672
pos += 1;
671673
}
672-
else if (!tryParseObjectHasOwnProperty(it_id)) break;
674+
else break;
673675
ch = commentWhitespace();
674676
}
675677
if (ch !== 41/*)*/) break;

lib/lexer.wasm

14 Bytes
Binary file not shown.

lib/lexer.wat

Lines changed: 88 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,107 +2879,113 @@
28792879
i32.const 2
28802880
i32.add
28812881
i32.store offset=20540
2882-
call 39
2883-
drop
28842882
block ;; label = @6
28852883
block ;; label = @7
2886-
i32.const 0
2887-
i32.load offset=20540
2888-
local.tee 0
2889-
local.get 2
2890-
local.get 6
2891-
call 65
2892-
br_if 0 (;@7;)
2893-
i32.const 0
2894-
local.get 0
2895-
local.get 7
2896-
i32.const 1
2897-
i32.shl
2898-
i32.add
2899-
i32.store offset=20540
29002884
call 39
2901-
i32.const 46
2902-
i32.ne
2903-
br_if 6 (;@1;)
2904-
i32.const 0
2905-
i32.const 0
2906-
i32.load offset=20540
2907-
i32.const 2
2908-
i32.add
2909-
i32.store offset=20540
2910-
call 39
2911-
i32.const 104
2885+
local.tee 0
2886+
i32.const 79
29122887
i32.ne
2913-
br_if 6 (;@1;)
2888+
br_if 0 (;@7;)
29142889
i32.const 0
29152890
i32.load offset=20540
2916-
local.tee 0
29172891
i32.const 2
29182892
i32.add
2919-
i32.const 97
2920-
i32.const 115
2921-
i32.const 79
2922-
i32.const 119
2923-
i32.const 110
2924-
i32.const 80
2925-
i32.const 114
2926-
i32.const 111
2927-
i32.const 112
2893+
i32.const 98
2894+
i32.const 106
29282895
i32.const 101
2929-
i32.const 114
2896+
i32.const 99
29302897
i32.const 116
2931-
i32.const 121
2932-
call 47
2898+
i32.const 46
2899+
call 38
29332900
i32.eqz
2934-
br_if 6 (;@1;)
2935-
i32.const 0
2936-
local.get 0
2937-
i32.const 28
2938-
i32.add
2939-
i32.store offset=20540
2940-
call 39
2941-
i32.const 40
2942-
i32.ne
2943-
br_if 6 (;@1;)
2944-
i32.const 0
2945-
i32.const 0
2946-
i32.load offset=20540
2947-
i32.const 2
2948-
i32.add
2949-
i32.store offset=20540
2950-
call 39
2951-
drop
2952-
i32.const 0
2953-
i32.load offset=20540
2954-
local.tee 0
2901+
br_if 0 (;@7;)
29552902
local.get 4
2956-
local.get 3
2957-
call 65
2958-
br_if 6 (;@1;)
2959-
i32.const 0
2960-
local.get 0
29612903
local.get 8
2962-
i32.const 1
2963-
i32.shl
2964-
i32.add
2965-
i32.store offset=20540
2966-
call 39
2967-
i32.const 41
2968-
i32.ne
2904+
call 51
2905+
i32.eqz
29692906
br_if 6 (;@1;)
2970-
i32.const 0
2971-
i32.const 0
2972-
i32.load offset=20540
2973-
i32.const 2
2974-
i32.add
2975-
i32.store offset=20540
29762907
br 1 (;@6;)
29772908
end
2909+
local.get 0
2910+
call 45
2911+
i32.eqz
2912+
br_if 0 (;@6;)
2913+
call 39
2914+
i32.const 46
2915+
i32.ne
2916+
br_if 5 (;@1;)
2917+
i32.const 0
2918+
i32.const 0
2919+
i32.load offset=20540
2920+
i32.const 2
2921+
i32.add
2922+
i32.store offset=20540
2923+
call 39
2924+
i32.const 104
2925+
i32.ne
2926+
br_if 5 (;@1;)
2927+
i32.const 0
2928+
i32.load offset=20540
2929+
local.tee 0
2930+
i32.const 2
2931+
i32.add
2932+
i32.const 97
2933+
i32.const 115
2934+
i32.const 79
2935+
i32.const 119
2936+
i32.const 110
2937+
i32.const 80
2938+
i32.const 114
2939+
i32.const 111
2940+
i32.const 112
2941+
i32.const 101
2942+
i32.const 114
2943+
i32.const 116
2944+
i32.const 121
2945+
call 47
2946+
i32.eqz
2947+
br_if 5 (;@1;)
2948+
i32.const 0
2949+
local.get 0
2950+
i32.const 28
2951+
i32.add
2952+
i32.store offset=20540
2953+
call 39
2954+
i32.const 40
2955+
i32.ne
2956+
br_if 5 (;@1;)
2957+
i32.const 0
2958+
i32.const 0
2959+
i32.load offset=20540
2960+
i32.const 2
2961+
i32.add
2962+
i32.store offset=20540
2963+
call 39
2964+
drop
2965+
i32.const 0
2966+
i32.load offset=20540
2967+
local.tee 0
29782968
local.get 4
2969+
local.get 3
2970+
call 65
2971+
br_if 5 (;@1;)
2972+
i32.const 0
2973+
local.get 0
29792974
local.get 8
2980-
call 51
2981-
i32.eqz
2975+
i32.const 1
2976+
i32.shl
2977+
i32.add
2978+
i32.store offset=20540
2979+
call 39
2980+
i32.const 41
2981+
i32.ne
29822982
br_if 5 (;@1;)
2983+
i32.const 0
2984+
i32.const 0
2985+
i32.load offset=20540
2986+
i32.const 2
2987+
i32.add
2988+
i32.store offset=20540
29832989
end
29842990
call 39
29852991
local.set 0

src/lexer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,10 @@ void tryParseObjectDefineOrKeys (bool keys) {
641641
if (ch != '!') break;
642642
pos += 1;
643643
ch = commentWhitespace();
644-
if (memcmp(pos, id_start, id_len * sizeof(uint16_t)) == 0) {
645-
pos += id_len;
644+
if (ch == 'O' && str_eq6(pos + 1, 'b', 'j', 'e', 'c', 't', '.')) {
645+
if (!tryParseObjectHasOwnProperty(it_id_start, it_id_len)) break;
646+
}
647+
else if (identifier(ch)) {
646648
ch = commentWhitespace();
647649
if (ch != '.') break;
648650
pos++;
@@ -659,7 +661,6 @@ void tryParseObjectDefineOrKeys (bool keys) {
659661
if (ch != ')') break;
660662
pos += 1;
661663
}
662-
else if (!tryParseObjectHasOwnProperty(it_id_start, it_id_len)) break;
663664
ch = commentWhitespace();
664665
}
665666
if (ch != ')') break;

test/_unit.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ suite('Lexer', () => {
228228
if (k !== 'default' && !Object.hasOwnProperty.call(exports, k)) exports[k] = external5[k];
229229
});
230230
231+
const not = require('not');
232+
Object.keys(not).forEach(function (k) {
233+
if (k !== 'default' && !a().hasOwnProperty(k)) exports[k] = not[k];
234+
});
235+
231236
Object.keys(external6).forEach(function (k) {
232-
if (k !== 'default' && !external6.hasOwnProperty(k)) exports[k] = external6[k];
237+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = external6[k];
233238
});
234239
235240
const external𤭢 = require('external𤭢');

0 commit comments

Comments
 (0)