ajaxorg/ace — pull request #1616 by fangel (2013-09-21 10:45:50+00:00)
Title: The require() and define() methods for workers does not conform to the AMDJS spec

Hi,

I've been in the process of creating my own mode that uses a web-worker for syntax- and type-checking. For this I needed to `require` both my own scripts, and 3rd party open-source scripts.

And in this I've stumbled across 2 problems with the `require()` and `define()` implementations in `lib/ace/lib/worker/worker.js`

### The define-function does not declare itself as a AMD-style `define` function, by exposing `define.amd`, like the spec says it should
The spec is located at https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property-

A lot of open-source libraries uses this property to see if they should expose themself as a AMD-module, or as a Node.js module, or... As indicated by the following search https://github.com/search?q=define.amd&type=Code&ref=searchresults, quite a lot of people uses the pattern `if(typeof define == "function" && typeof define.amd == "object" && define.amd)` or variants of it.

### The define-function does not work with dependencies listed in the `define()`-call.

This mean that all code on the form `define(['dep1', ..., 'depN'], function(dep1, ..., depN) { .... })` does not work.

If you look at the specs https://github.com/amdjs/amdjs-api/wiki/AMD#define-function-, this should be supported - especially when the the `define()` function-prototype you give is `function(id, deps, factory)`.

In other words, the two preambles

```
define(['dependency'], function(Dependency) {
```
and
```
define(function(require) {
var Dependency = require('dependency')
```
should be have exactly the same behaviour, but they do not. In the case of the first, the member-variable `Dependency` is now the require()-function, which leads to hard to debug problems. The error-message given, is simply `Could not load file ...../[value-of-argument-to-the-function].js`, because it tries to require the value of the input.

This means that any 3rd party code you wish to integrate into web-workers are limited to those that uses the CommonJS compatibility later for RequireJS.

--

The added patch simply solves 1), because I have not yet had time to look at solving 2), and have instead resorted to simply rewriting all my own files to use the CommonJS compatibility-mode.

(Sorry for the line-ending change at the bottom of the patch, it was introduced by the GitHub inline editor)

Kind Regards
Morten