|
| 1 | +/** |
| 2 | + * Hermes Compatibility Test |
| 3 | + * |
| 4 | + * Asserts dist/index.cjs contains no bare import() expressions. |
| 5 | + * hermesc (React Native bytecode compiler) rejects import() at parse time — |
| 6 | + * before dead-code elimination — so the syntax must be physically absent. |
| 7 | + * The only allowed occurrence is inside a new Function() string body, which |
| 8 | + * is opaque to all static parsers including hermesc. |
| 9 | + * |
| 10 | + * Run with: node test/bundle-hermes-compat.test.cjs |
| 11 | + */ |
| 12 | + |
| 13 | +const assert = require('assert') |
| 14 | +const fs = require('fs') |
| 15 | +const path = require('path') |
| 16 | + |
| 17 | +console.log('Testing Hermes (React Native) compatibility...\n') |
| 18 | + |
| 19 | +const cjsPath = path.join(__dirname, '../dist/index.cjs') |
| 20 | +const cjs = fs.readFileSync(cjsPath, 'utf8') |
| 21 | +const lines = cjs.split('\n') |
| 22 | + |
| 23 | +let bareImportCount = 0 |
| 24 | +for (let i = 0; i < lines.length; i++) { |
| 25 | + const line = lines[i] |
| 26 | + if (!line.includes('import(')) continue |
| 27 | + if (!line.includes('new Function(')) { |
| 28 | + bareImportCount++ |
| 29 | + console.error( |
| 30 | + `❌ Bare import() at line ${i + 1}:\n ${line.trim()}\n` + |
| 31 | + ` This breaks hermesc (Hermes bytecode compiler for React Native).` |
| 32 | + ) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +assert.strictEqual( |
| 37 | + bareImportCount, |
| 38 | + 0, |
| 39 | + `${bareImportCount} bare import() expression(s) in dist/index.cjs — breaks React Native Hermes builds.` |
| 40 | +) |
| 41 | + |
| 42 | +console.log('1. No bare import() expressions in dist/index.cjs') |
| 43 | +console.log(' ✅ Hermes-safe (React Native compatible)\n') |
| 44 | +console.log('🎉 Hermes compatibility test passed!') |
0 commit comments