Skip to content

Commit c4ec0b2

Browse files
authored
allow for named exports when importing (#62)
Adds support for importing as named exports from `mjs` modules: ```js import { po, mo } from 'gettext-parser'; ``` Recent node does some parsing using `cjs-module-lexer`, and it can understand lines like `module.exports.po`, but it can't understand `module.exports = { po: ... }`.
1 parent f383dc8 commit c4ec0b2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
const { parse, stream } = require('./lib/poparser');
22

3-
module.exports = {
4-
po: {
5-
parse,
6-
createParseStream: stream,
7-
compile: require('./lib/pocompiler')
8-
},
3+
module.exports.po = {
4+
parse,
5+
createParseStream: stream,
6+
compile: require('./lib/pocompiler')
7+
};
98

10-
mo: {
11-
parse: require('./lib/moparser'),
12-
compile: require('./lib/mocompiler')
13-
}
9+
module.exports.mo = {
10+
parse: require('./lib/moparser'),
11+
compile: require('./lib/mocompiler')
1412
};

test/module.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect } from 'chai';
2+
import { po, mo } from '../index.js';
3+
4+
describe('esm module', () => {
5+
it('should allow named imports', () => {
6+
expect(po.parse).to.be.a('function');
7+
expect(po.compile).to.be.a('function');
8+
expect(mo.parse).to.be.a('function');
9+
expect(mo.compile).to.be.a('function');
10+
});
11+
});

0 commit comments

Comments
 (0)