Replies: 3 comments
-
These are some pretty interesting ideas and something we would like to explore eventually. It has some overlap with #10 which we also want to explore in the future. The current major roadblock is that the Civet AST isn't yet stable (though it is getting closer). It might also be nice to be able to scope the directives to specific blocks as well. It may also take a bit of time to work out all the design details but having it be an experimental opt in flag would be a great way to start figuring things out. Thanks for the suggestion! |
Beta Was this translation helpful? Give feedback.
-
Yes, it's more like experiment, maybe the easiest way could be a config option to supply |
Beta Was this translation helpful? Give feedback.
-
I played with babel transformer and this approach a bit. The most useful feature is replacing default Array and Object literals with other implementations. Say |
Beta Was this translation helpful? Give feedback.
-
Thinking about possible alterations of JS semantics, disabled by default and enabled with flag.
Customizable operators, on any object, a bit dirty, with types.
Following transformation required.
And so it would be possible math support
Vec(1, 2) + Vec(2, 4)
,Vec(1, 2)[1]
sorting for arbitraryobjects if it defined
compare
, proper equality check, properly workingin
like'a' in ['a', 'b'] # => true
ifcontains
defined, etc.A bit dirty, as it would require to define
Number/String/Etc.prototype.contains/plus/equals/etc
but it shouldn't be that bad. Also it should work with TypeScript.Extend Array and Object, clean, with types.
So it would be possible intercept object/array creation and alter it or return other implementation. So finally we don't need
Object.keys(o)
noncense, and it's going to beo.keys()
. Maybe add more methods likeo.merge(other)
,o.size()
etc.Same with
Array
, fixsort|reverse|etc
mutable versions and replace it with immutable functions, implementsort
properly with comparators. ImproveArray
interface.Clean, changes isolated, no built-in or library code affected, and it also should work with TypeScript.
Method call interceptor, almost clean, not sure if types would work.
Relatively safely extend built in types, only one property
extensions
will be added to pototype, and some other use cases.With something like
Implementation
Could be done as plugins, if Civet would accept custom
transform(ast): ast
function, same way as babel does.I created these transformations for babel for example the code for object and array wrappers done as. But it can't be done on the Civet output code, transformation needs to be done on the Civet AST.
Beta Was this translation helpful? Give feedback.
All reactions