Skip to content

Commit

Permalink
fix(extend-lion-docs): support multi line exports
Browse files Browse the repository at this point in the history
  • Loading branch information
daKmoR committed Jun 16, 2021
1 parent 835c280 commit c5992d6
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .changeset/giant-deers-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'rocket-preset-extend-lion-docs': patch
---

Support multi line exports and comments in exports

```js
export {
// html,
calculateSum,
offsetValue,
} from './src/helpers.js';
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import path from 'path';
// @ts-ignore
import { init, parse } from 'es-module-lexer/dist/lexer.js';

/**
* @param {string} value
* @returns {boolean}
*/
function isComment(value) {
return value.startsWith('//') || value.startsWith('/*') || value.startsWith('*/');
}

/**
* @param {string} src
* @returns
Expand All @@ -16,12 +24,16 @@ function getImportNames(src) {
const full = src.substring(importObj.ss, importObj.se);
if (full.includes('{')) {
const namesString = full.substring(full.indexOf('{') + 1, full.indexOf('}'));
namesString.split(',').forEach(name => {
names.push(name.trim());
namesString.split('\n').forEach(nameLine => {
nameLine.split(',').forEach(name => {
const trimmedNamed = name.trim();
if (trimmedNamed && !isComment(trimmedNamed)) {
names.push(name.trim());
}
});
});
}
}

return names;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
//
html,
CSSResult,
// something,
adoptStyles,
} from 'lit';
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@lion/core",
"version": "0.5.0",
"description": "Vertically stacked list of invokers that can be clicked to reveal or hide content associated with them.",
"license": "MIT",
"author": "ing-bank",
"homepage": "https://github.com/ing-bank/lion/",
"repository": {
"type": "git",
"url": "https://github.com/ing-bank/lion.git",
"directory": "packages/accordion"
},
"main": "index.js",
"module": "index.js",
"files": [
"*.d.ts",
"*.js",
"custom-elements.json",
"docs",
"src",
"test",
"test-helpers",
"translations",
"types"
],
"scripts": {
"custom-elements-manifest": "custom-elements-manifest analyze --litelement --exclude \"docs/**/*\" \"test-helpers/**/*\"",
"debug": "cd ../../ && npm run debug -- --group accordion",
"debug:firefox": "cd ../../ && npm run debug:firefox -- --group accordion",
"debug:webkit": "cd ../../ && npm run debug:webkit -- --group accordion",
"publish-docs": "node ../../packages-node/publish-docs/src/cli.js --github-url https://github.com/ing-bank/lion/ --git-root-dir ../../",
"prepublishOnly": "npm run publish-docs && npm run custom-elements-manifest",
"test": "cd ../../ && npm run test:browser -- --group accordion"
},
"sideEffects": [
"lion-accordion.js"
],
"dependencies": {
"@lion/core": "0.17.0"
},
"keywords": [
"accordion",
"lion",
"web-components"
],
"publishConfig": {
"access": "public"
},
"customElementsManifest": "custom-elements.json",
"exports": {
".": "./index.js",
"./docs/": "./docs/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,52 @@ describe('generateExtendDocsConfig', () => {
]);
});

it('can handle exports with multiple lines', async () => {
const result = await execute('fixtures/multi-line');

expect(result).to.deep.equal([
{
name: '@lion/core - html',
variable: {
from: 'html',
to: 'html',
paths: [
{
from: '@lion/core',
to: 'ing-web/core',
},
],
},
},
{
name: '@lion/core - CSSResult',
variable: {
from: 'CSSResult',
to: 'CSSResult',
paths: [
{
from: '@lion/core',
to: 'ing-web/core',
},
],
},
},
{
name: '@lion/core - adoptStyles',
variable: {
from: 'adoptStyles',
to: 'adoptStyles',
paths: [
{
from: '@lion/core',
to: 'ing-web/core',
},
],
},
},
]);
});

it('can customize the target', async () => {
const result = await execute('fixtures/accordion', {
classPrefix: 'Wolf',
Expand Down

0 comments on commit c5992d6

Please sign in to comment.