Permalink
Browse files

Moved registerExtension() into 'transform' module and renamed it 'cin…

…ch'.
  • Loading branch information...
1 parent f476a99 commit e18d46c11f66df9615749a426e3b6c7be4f67e81 @pguillory committed Feb 24, 2011
Showing with 40 additions and 52 deletions.
  1. +1 −3 index.js
  2. +39 −33 lib/{transform.js → cinch.js}
  3. +0 −16 lib/register.js
  4. 0 test/tests/1. Functions/1. Returning a value/{index.js.after.json → index.js.parsed.json}
  5. 0 test/tests/1. Functions/1. Returning a value/{index.js.before.json → index.js_.parsed.json}
  6. 0 test/tests/1. Functions/2. Implicitly return undefined/{index.js.after.json → index.js.parsed.json}
  7. 0 .../tests/1. Functions/2. Implicitly return undefined/{index.js.before.json → index.js_.parsed.json}
  8. 0 test/tests/1. Functions/3. Throws propagate/{index.js.after.json → index.js.parsed.json}
  9. 0 test/tests/1. Functions/3. Throws propagate/{index.js.before.json → index.js_.parsed.json}
  10. 0 test/tests/1. Functions/4. Call a regular function/{index.js.after.json → index.js.parsed.json}
  11. 0 test/tests/1. Functions/4. Call a regular function/{index.js.before.json → index.js_.parsed.json}
  12. 0 test/tests/1. Functions/4b. Call a transformed function/{index.js.after.json → index.js.parsed.json}
  13. 0 ...tests/1. Functions/4b. Call a transformed function/{index.js.before.json → index.js_.parsed.json}
  14. 0 test/tests/1. Functions/5. Pass through async result/{index.js.after.json → index.js.parsed.json}
  15. 0 test/tests/1. Functions/5. Pass through async result/{index.js.before.json → index.js_.parsed.json}
  16. 0 ...turn expression containing transformed function call/{index.js.after.json → index.js.parsed.json}
  17. 0 ...rn expression containing transformed function call/{index.js.before.json → index.js_.parsed.json}
  18. 0 test/tests/1. Functions/9. Function defined in var/{index.js.after.json → index.js.parsed.json}
  19. 0 test/tests/1. Functions/9. Function defined in var/{index.js.before.json → index.js_.parsed.json}
  20. 0 ...Streamlined function call/1. In semicolon expression/{index.js.after.json → index.js.parsed.json}
  21. 0 ...reamlined function call/1. In semicolon expression/{index.js.before.json → index.js_.parsed.json}
  22. 0 ...s/2. Streamlined function call/2. In var initializer/{index.js.after.json → index.js.parsed.json}
  23. 0 ...2. Streamlined function call/2. In var initializer/{index.js.before.json → index.js_.parsed.json}
  24. 0 ...ests/2. Streamlined function call/3. In return value/{index.js.after.json → index.js.parsed.json}
  25. 0 ...ts/2. Streamlined function call/3. In return value/{index.js.before.json → index.js_.parsed.json}
  26. 0 ...sts/2. Streamlined function call/4. In if expression/{index.js.after.json → index.js.parsed.json}
  27. 0 ...s/2. Streamlined function call/4. In if expression/{index.js.before.json → index.js_.parsed.json}
  28. 0 ...s/2. Streamlined function call/5. In throw exception/{index.js.after.json → index.js.parsed.json}
  29. 0 ...2. Streamlined function call/5. In throw exception/{index.js.before.json → index.js_.parsed.json}
  30. 0 test/tests/2. Streamlined function call/6. In dot/{index.js.after.json → index.js.parsed.json}
  31. 0 test/tests/2. Streamlined function call/6. In dot/{index.js.before.json → index.js_.parsed.json}
  32. 0 test/tests/3. While/1. Works/{index.js.after.json → index.js.parsed.json}
  33. 0 test/tests/3. While/1. Works/{index.js.before.json → index.js_.parsed.json}
  34. 0 test/tests/3. While/2. Body/{index.js.after.json → index.js.parsed.json}
  35. 0 test/tests/3. While/2. Body/{index.js.before.json → index.js_.parsed.json}
  36. 0 test/tests/3. While/3. Break/{index.js.after.json → index.js.parsed.json}
  37. 0 test/tests/3. While/3. Break/{index.js.before.json → index.js_.parsed.json}
  38. 0 test/tests/3. While/4. Break in else/{index.js.after.json → index.js.parsed.json}
  39. 0 test/tests/3. While/4. Break in else/{index.js.before.json → index.js_.parsed.json}
  40. 0 test/tests/3. While/5. Continue/{index.js.after.json → index.js.parsed.json}
  41. 0 test/tests/3. While/5. Continue/{index.js.before.json → index.js_.parsed.json}
  42. 0 test/tests/4. For/1. Works/{index.js.after.json → index.js.parsed.json}
  43. 0 test/tests/4. For/1. Works/{index.js.before.json → index.js_.parsed.json}
  44. 0 test/tests/4. For/2. Iterates properly/{index.js.after.json → index.js.parsed.json}
  45. 0 test/tests/4. For/2. Iterates properly/{index.js.before.json → index.js_.parsed.json}
  46. 0 test/tests/4. For/3. Continue/{index.js.after.json → index.js.parsed.json}
  47. 0 test/tests/4. For/3. Continue/{index.js.before.json → index.js_.parsed.json}
  48. 0 test/tests/5. Switch/1. SFC in discriminant/{index.js.after.json → index.js.parsed.json}
  49. 0 test/tests/5. Switch/1. SFC in discriminant/{index.js.before.json → index.js_.parsed.json}
  50. 0 test/tests/5. Switch/2. SFC in case/{index.js.after.json → index.js.parsed.json}
  51. 0 test/tests/5. Switch/2. SFC in case/{index.js.before.json → index.js_.parsed.json}
  52. 0 test/tests/6. Try-catch/8. In a try block/{index.js.after.json → index.js.parsed.json}
  53. 0 test/tests/6. Try-catch/8. In a try block/{index.js.before.json → index.js_.parsed.json}
  54. 0 test/tests/6. Try-catch/8b. In a catch block/{index.js.after.json → index.js.parsed.json}
  55. 0 test/tests/6. Try-catch/8b. In a catch block/{index.js.before.json → index.js_.parsed.json}
  56. 0 test/tests/6. Try-catch/8c. In a finally block/{index.js.after.json → index.js.parsed.json}
  57. 0 test/tests/6. Try-catch/8c. In a finally block/{index.js.before.json → index.js_.parsed.json}
  58. 0 test/tests/7. For-in/1. Basic use/{index.js.after.json → index.js.parsed.json}
  59. 0 test/tests/7. For-in/1. Basic use/{index.js.before.json → index.js_.parsed.json}
  60. 0 test/tests/7. For-in/2. SFC in object clause/{index.js.after.json → index.js.parsed.json}
  61. 0 test/tests/7. For-in/2. SFC in object clause/{index.js.before.json → index.js_.parsed.json}
  62. 0 test/tests/8. If/1. thenPart is single return/{index.js.after.json → index.js.parsed.json}
  63. 0 test/tests/8. If/1. thenPart is single return/{index.js.before.json → index.js_.parsed.json}
  64. 0 test/tests/8. If/1b. elsePart is single return/{index.js.after.json → index.js.parsed.json}
  65. 0 test/tests/8. If/1b. elsePart is single return/{index.js.before.json → index.js_.parsed.json}
  66. 0 test/tests/9. Throws in expressions/1. Return value/{index.js.after.json → index.js.parsed.json}
  67. 0 test/tests/9. Throws in expressions/1. Return value/{index.js.before.json → index.js_.parsed.json}
  68. 0 ...sts/9. Throws in expressions/2. Semicolon expression/{index.js.after.json → index.js.parsed.json}
  69. 0 ...s/9. Throws in expressions/2. Semicolon expression/{index.js.before.json → index.js_.parsed.json}
  70. 0 test/tests/9. Throws in expressions/3. Var initializer/{index.js.after.json → index.js.parsed.json}
  71. 0 .../tests/9. Throws in expressions/3. Var initializer/{index.js.before.json → index.js_.parsed.json}
  72. 0 test/tests/9. Throws in expressions/4. If condition/{index.js.after.json → index.js.parsed.json}
  73. 0 test/tests/9. Throws in expressions/4. If condition/{index.js.before.json → index.js_.parsed.json}
View
@@ -1,3 +1 @@
-exports.registerExtension = require('./lib/register').registerExtension;
-exports.transformSource = require("./lib/transform").transformSource;
-exports.transformFile = require("./lib/transform").transformFile;
+module.exports = require('./lib/cinch.js')
@@ -13,57 +13,61 @@ var idents = require('./idents')
var banner = "/*** Generated by Cinch ***/\n";
-exports.transformSource = function(source) {
- idents.reset()
- var script = Narcissus.parser.parse(source)
- transform_script(script)
- var transformed = pp(script) + '\n'
- return transformed
-}
+exports.registerExtension = function(options) {
+ options = options || {}
-exports.transformFile = function(filename_, options) {
- var dirname = path.dirname(filename_)
- var ext = path.extname(filename_)
- var basename = path.basename(filename_, ext)
- var filename = path.join(dirname, basename + '.js')
+ // force require() to check for .js_ before .js
+ var js_extension = require.extensions['.js']
+ delete require.extensions['.js']
- idents.reset()
+ require.extensions[options.extension || '.js_'] = function(module, filename_) {
+ var dirname = path.dirname(filename_)
+ var ext = path.extname(filename_)
+ var basename = path.basename(filename_, ext)
+ var filename = path.join(dirname, basename + '.js')
- var source = fs.readFileSync(filename_, 'utf8');
+ var source = fs.readFileSync(filename_, 'utf8');
- if (options.saveParseTree) {
try {
- var script = Narcissus.parser.parse(source)
+ Narcissus.parser.parse(source)
} catch (err) {
module._compile(source, filename_)
throw err
}
- strip(script)
- fs.writeFileSync(filename + '.before.json', JSON.stringify(script), 'utf8')
- }
- try {
+ if (options.saveParseTree) {
+ var script = Narcissus.parser.parse(source)
+ strip(script)
+ fs.writeFileSync(filename_ + '.parsed.json', JSON.stringify(script), 'utf8')
+
+ var script = Narcissus.parser.parse(source)
+ transform_script(script)
+ strip(script)
+ fs.writeFileSync(filename + '.parsed.json', JSON.stringify(script), 'utf8')
+ }
+
var script = Narcissus.parser.parse(source)
- } catch (err) {
- module._compile(source, filename_)
- throw err
- }
- transform_script(script)
- var transformed = pp(script) + '\n'
+ transform_script(script)
+ var transformed = pp(script) + '\n'
+
+ if (options.saveSource) {
+ fs.writeFileSync(filename, transformed, 'utf8');
+ }
- if (options.saveParseTree) {
- strip(script)
- fs.writeFileSync(filename + '.after.json', JSON.stringify(script), 'utf8')
+ module._compile(transformed, filename)
}
- if (options.saveSource) {
- fs.writeFileSync(filename, transformed, 'utf8');
- }
+ require.extensions['.js'] = js_extension
+}
- return transformed
+exports.transformSource = function(source) {
+ var script = Narcissus.parser.parse(source)
+ transform_script(script)
+ return pp(script) + '\n'
}
function transform_script(script) {
+ idents.reset()
scan_for_functions_to_transform(script).forEach(transform_function)
replace_passthrough_callbacks(script)
replace_passthrough_functions(script)
@@ -153,10 +157,12 @@ function is_passthrough_function(n) {
}
function foo() {
bar()
+ baz()
}
// ...to...
{
bar()
+ baz()
}
*/
function inline_functions_only_called_once(script) {
View
@@ -1,16 +0,0 @@
-var cinch = require('..')
-
-exports.registerExtension = function(options) {
- options = options || {}
-
- // force require() to check for .js_ before .js
- var js_extension = require.extensions['.js']
- delete require.extensions['.js']
-
- require.extensions[options.extension || '.js_'] = function(module, filename) {
- var content = cinch.transformFile(filename, options)
- module._compile(content, filename)
- }
-
- require.extensions['.js'] = js_extension
-}

0 comments on commit e18d46c

Please sign in to comment.