Comments (4)
Hmm interesting. Wonder why classes don’t make methods enumerable.
Your code, however:
const isConstructorFunction = (value) => Boolean(value && value.prototype && value.prototype.constructor);
Will accept any function. isConstructorFunction(function () {}) // => true
from unified.
Yes right, because function(){}
could be used as constructor. But () => {}
couldn't.
I think the only way to do handle that is to replace:
Lines 270 to 274 in 612d8dd
with:
let result = null;
if (newable(Parser)) {
// "Parser" is a class or a function (but not a generator nor an arrow function)
result = new Parser(String(file), file)
if (result.hasOwnProperty("parse")) {
result = result.parse()
}
} else {
result = Parser(String(file), file)
}
return result
Use a simple function a constructor isn't an issue :
new function(){return ["test"]} // > Array [ "test" ]
from unified.
I think that works, and even simpler: the else statement isn't needed from what it seems. Could you try a PR for this?
from unified.
Unfortunately this will not work for compiler
. Because when compiler
is a normal function, it should return a string, and strings can’t be returned from a constructor.
from unified.
Related Issues (20)
- Update vfile to 4.2.1 HOT 1
- Logo not readable on github dark mode HOT 1
- Next major for the ecosystem HOT 46
- Dependencies need to be ESM HOT 6
- 3rd overload signature of `FrozenProcessor.run` should accept `ParseTree` instead of `CompileTree` HOT 5
- this.use() doesn't respect plugin order when combined with unified().use() HOT 6
- Support async compilers HOT 31
- Rethink how `*-stringify` should work HOT 16
- Throw on preset w/ neither `settings` nor `plugins` HOT 1
- unify AST types HOT 1
- Support `Node` typeParam in `Pluggable` and `PluggableList` HOT 9
- Notion Block AST HOT 4
- Error: No overload matches this call after library update. HOT 5
- Type errors on new major version → 11.0.2 HOT 5
- TypeScript error when doing simple unified markdown pipeline HOT 3
- CallableInstance throws error in older ECMA 5 targets HOT 6
- remove `is-plain-obj` deps HOT 9
- Make VFileContents generic to support processors that return objects HOT 3
- tsc reports incorrect / missing types HOT 14
- VFile types do not support property result HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unified.