Tag: sweet.js

在Node.js中将SweetJS编译为string

从shell中,我可以调用Sweet.js编译器。 sjs -m macro-providing-module -o output-directory/file.js input-directory/file.sjs 我怎么能做到这一点从一个Node.js模块内部,而不是输出到指定的文件,我得到的编译输出为string? var sweetjs = require('sweet.js'); var input = require('fs').readSync('input-directory/file.sjs'); var module = 'macro-providing-module'; var output = sweetjs(/* ??? */);

如何打破SweetJS卫生局部variables?

我正在尝试在我的项目中使用SweetJS。 为了更好地理解和学习SweetJS,我想我会从一个简单的“class”macros开始(我知道有一些存在,只是在这里玩…)。 我似乎无法让SweetJS停止与我的本地variables“自我”和“superCall”混乱。 任何想法我做错了什么? 我想var self=this保持var self=this而不是被损坏。 macro class { case { _ $name extends $parent { constructor $cargs { $cbody … } $($mname $margs { $mbody … } ) … } } => { return #{ function $name $cargs { var self=this,superCall=$parent.prototype; $cbody … } $name.prototype = Object.create($parent.prototype); ($name.prototype.$mname = function $margs {var self=this,superCall=$parent.prototype; […]