From 02f4cb75dd69ad5bce45b24d44bc2926d833d694 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 15 Mar 2010 22:53:25 -0700 Subject: [PATCH] removing deprecated references to process.mixin in favor of helpers.extend for Node 0.1.32 --- Cakefile | 5 +++-- bin/cake | 3 ++- bin/coffee | 3 ++- documentation/coffee/cake_tasks.coffee | 2 -- examples/web_server.coffee | 4 ++-- lib/cake.js | 5 +++-- lib/coffee-script.js | 5 +++-- lib/helpers.js | 12 +++++++++++- lib/repl.js | 5 +++-- src/cake.coffee | 3 ++- src/coffee-script.coffee | 3 ++- src/helpers.coffee | 4 ++++ src/repl.coffee | 3 ++- 13 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Cakefile b/Cakefile index e1e71de8..a9a6cb0a 100644 --- a/Cakefile +++ b/Cakefile @@ -1,4 +1,5 @@ fs: require 'fs' +helpers: require('./helpers').helpers CoffeeScript: require './lib/coffee-script' # Run a CoffeeScript through our node/coffee interpreter. @@ -68,11 +69,11 @@ task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', -> task 'test', 'run the CoffeeScript language test suite', -> - process.mixin require 'assert' + helpers.extend global, require 'assert' test_count: 0 start_time: new Date() [original_ok, original_throws]: [ok, throws] - process.mixin { + helpers.extend global, { ok: (args...) -> test_count += 1; original_ok(args...) throws: (args...) -> test_count += 1; original_throws(args...) CoffeeScript: CoffeeScript diff --git a/bin/cake b/bin/cake index da7419e0..d6ca0771 100755 --- a/bin/cake +++ b/bin/cake @@ -1,6 +1,7 @@ #!/usr/bin/env node -process.mixin(require('sys')); +require('./../lib/helpers').helpers.extend(global, require('sys')); + var path = require('path'); var fs = require('fs'); var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); diff --git a/bin/coffee b/bin/coffee index 2d026f52..d5dec249 100755 --- a/bin/coffee +++ b/bin/coffee @@ -1,6 +1,7 @@ #!/usr/bin/env node -process.mixin(require('sys')); +require('./../lib/helpers').helpers.extend(global, require('sys')); + var path = require('path'); var fs = require('fs'); var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); diff --git a/documentation/coffee/cake_tasks.coffee b/documentation/coffee/cake_tasks.coffee index f5f8b535..40b4640a 100644 --- a/documentation/coffee/cake_tasks.coffee +++ b/documentation/coffee/cake_tasks.coffee @@ -1,5 +1,3 @@ -process.mixin require 'assert' - task 'test', 'run each of the unit tests', -> for test in test_files fs.readFile test, (err, code) -> eval coffee.compile code diff --git a/examples/web_server.coffee b/examples/web_server.coffee index b9927ef1..5ee5c7af 100644 --- a/examples/web_server.coffee +++ b/examples/web_server.coffee @@ -1,6 +1,6 @@ # Contributed by Jason Huggins -process.mixin require 'sys' +sys: require 'sys' http: require 'http' server: http.createServer (req, res) -> @@ -10,4 +10,4 @@ server: http.createServer (req, res) -> server.listen 3000 -puts "Server running at http://localhost:3000/" +sys.puts "Server running at http://localhost:3000/" diff --git a/lib/cake.js b/lib/cake.js index 641673aa..46ecf89d 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -1,5 +1,5 @@ (function(){ - var CoffeeScript, fs, no_such_task, oparse, options, optparse, path, print_tasks, switches, tasks; + var CoffeeScript, fs, helpers, no_such_task, oparse, options, optparse, path, print_tasks, switches, tasks; var __hasProp = Object.prototype.hasOwnProperty; // `cake` is a simplified version of [Make](http://www.gnu.org/software/make/) // ([Rake](http://rake.rubyforge.org/), [Jake](http://github.com/280north/jake)) @@ -10,6 +10,7 @@ // External dependencies. fs = require('fs'); path = require('path'); + helpers = require('./helpers').helpers; optparse = require('./optparse'); CoffeeScript = require('./coffee-script'); // Keep track of the list of defined tasks, the accepted options, and so on. @@ -18,7 +19,7 @@ switches = []; oparse = null; // Mixin the top-level Cake functions for Cakefiles to use directly. - process.mixin({ + helpers.extend(global, { // Define a Cake task with a short name, a sentence description, // and the function to run as the action itself. task: function task(name, description, action) { diff --git a/lib/coffee-script.js b/lib/coffee-script.js index a6787691..6af3a8fa 100644 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -1,5 +1,5 @@ (function(){ - var Lexer, lexer, parser, path, process_scripts; + var Lexer, helpers, lexer, parser, path, process_scripts; // CoffeeScript can be used both on the server, as a command-line compiler based // on Node.js/V8, or to run CoffeeScripts directly in the browser. This module // contains the main entry functions for tokenzing, parsing, and compiling source @@ -8,10 +8,11 @@ // execute all scripts present in `text/coffeescript` tags. // Set up dependencies correctly for both the server and the browser. if ((typeof process !== "undefined" && process !== null)) { - process.mixin(require('./nodes')); path = require('path'); Lexer = require('./lexer').Lexer; parser = require('./parser').parser; + helpers = require('./helpers').helpers; + helpers.extend(global, require('./nodes')); } else { this.exports = (this.CoffeeScript = {}); Lexer = this.Lexer; diff --git a/lib/helpers.js b/lib/helpers.js index ddaeb12b..ec5b1943 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,5 +1,5 @@ (function(){ - var balanced_string, compact, count, del, flatten, helpers, include, merge, starts; + var balanced_string, compact, count, del, extend, flatten, helpers, include, merge, starts; var __hasProp = Object.prototype.hasOwnProperty; // This file contains the common helper functions that we'd like to share among // the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten @@ -60,6 +60,16 @@ } return fresh; }); + // Extend a source object with the properties of another object (shallow copy). + helpers.extend = (extend = function extend(object, properties) { + var _a, _b, key, val; + _a = []; _b = properties; + for (key in _b) { if (__hasProp.call(_b, key)) { + val = _b[key]; + _a.push(((object[key] = val))); + }} + return _a; + }); // Return a completely flattened version of an array. Handy for getting a // list of `children` from the nodes. helpers.flatten = (flatten = function flatten(array) { diff --git a/lib/repl.js b/lib/repl.js index 0cc489c0..2c73cfe5 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1,15 +1,16 @@ (function(){ - var CoffeeScript, prompt, run; + var CoffeeScript, helpers, prompt, run; // A very simple Read-Eval-Print-Loop. Compiles one line at a time to JavaScript // and evaluates it. Good for simple tests, or poking around the **Node.js** API. // Using it looks like this: // coffee> puts "$num bottles of beer" for num in [99..1] // Require the **coffee-script** module to get access to the compiler. CoffeeScript = require('./coffee-script'); + helpers = require('./helpers').helpers; // Our prompt. prompt = 'coffee> '; // Quick alias for quitting the REPL. - process.mixin({ + helpers.extend(global, { quit: function quit() { return process.exit(0); } diff --git a/src/cake.coffee b/src/cake.coffee index 180acd9b..53c4d226 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -9,6 +9,7 @@ # External dependencies. fs: require 'fs' path: require 'path' +helpers: require('./helpers').helpers optparse: require './optparse' CoffeeScript: require './coffee-script' @@ -19,7 +20,7 @@ switches: [] oparse: null # Mixin the top-level Cake functions for Cakefiles to use directly. -process.mixin { +helpers.extend global, { # Define a Cake task with a short name, a sentence description, # and the function to run as the action itself. diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index a592ca09..a8e6d133 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -8,10 +8,11 @@ # Set up dependencies correctly for both the server and the browser. if process? - process.mixin require './nodes' path: require 'path' Lexer: require('./lexer').Lexer parser: require('./parser').parser + helpers: require('./helpers').helpers + helpers.extend global, require './nodes' else this.exports: this.CoffeeScript: {} Lexer: this.Lexer diff --git a/src/helpers.coffee b/src/helpers.coffee index d395a32a..27896036 100644 --- a/src/helpers.coffee +++ b/src/helpers.coffee @@ -35,6 +35,10 @@ helpers.merge: merge: (options, overrides) -> (fresh[key]: val) for key, val of overrides if overrides fresh +# Extend a source object with the properties of another object (shallow copy). +helpers.extend: extend: (object, properties) -> + (object[key]: val) for key, val of properties + # Return a completely flattened version of an array. Handy for getting a # list of `children` from the nodes. helpers.flatten: flatten: (array) -> diff --git a/src/repl.coffee b/src/repl.coffee index c7adcbef..f0cb54df 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -6,12 +6,13 @@ # Require the **coffee-script** module to get access to the compiler. CoffeeScript: require './coffee-script' +helpers: require('./helpers').helpers # Our prompt. prompt: 'coffee> ' # Quick alias for quitting the REPL. -process.mixin { +helpers.extend global, { quit: -> process.exit(0) }