Skip to content

Commit

Permalink
Merge branch 'release/v1.8' into fix/AG-17905
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Dec 20, 2022
2 parents 25c9820 + f0fbd11 commit 09626a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ And also there is a module at `dist/scriptlets.js` which has been exported to a

```javascript
/**
* Returns scriptlet code
* Returns scriptlet code by param
* @param {Source} source
* @returns {string}
* @returns {string|null} scriptlet code
* @throws on unknown scriptlet name
*/
scriptlets.invoke(source);
```
Expand Down
14 changes: 11 additions & 3 deletions src/scriptlets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ import { getScriptletFunction } from '../../tmp/scriptlets-func';
* Returns scriptlet code by param
* @param {Source} source
* @returns {string|null} scriptlet code
* @throws on unknown scriptlet name
*/
function getScriptletCode(source) {
if (!validator.isValidScriptletName(source.name)) {
return null;
}

const scriptletFunction = getScriptletFunction(source.name).toString();
const scriptletFunction = getScriptletFunction(source.name);
// In case isValidScriptletName check will pass invalid scriptlet name,
// for example when there is a bad alias
if (typeof scriptletFunction !== 'function') {
throw new Error(`Error: cannot invoke scriptlet with name: '${source.name}'`);
}
const scriptletFunctionString = scriptletFunction.toString();

const result = source.engine === 'corelibs' || source.engine === 'test'
? wrapInNonameFunc(scriptletFunction)
: passSourceAndProps(source, scriptletFunction);
? wrapInNonameFunc(scriptletFunctionString)
: passSourceAndProps(source, scriptletFunctionString);
return result;
}

Expand Down

0 comments on commit 09626a3

Please sign in to comment.