Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3382B200B92 for ; Wed, 28 Sep 2016 12:26:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3225D160AD4; Wed, 28 Sep 2016 10:26:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5459A160AB4 for ; Wed, 28 Sep 2016 12:26:07 +0200 (CEST) Received: (qmail 84487 invoked by uid 500); 28 Sep 2016 10:26:06 -0000 Mailing-List: contact dev-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list dev@flex.apache.org Received: (qmail 84475 invoked by uid 99); 28 Sep 2016 10:26:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2016 10:26:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 9622E1A5F5B for ; Wed, 28 Sep 2016 10:26:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.493 X-Spam-Level: ** X-Spam-Status: No, score=2.493 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_BL_SPAMCOP_NET=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=0.614, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 1FySVQAPkCNi for ; Wed, 28 Sep 2016 10:26:04 +0000 (UTC) Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 217F15F2C4 for ; Wed, 28 Sep 2016 10:26:04 +0000 (UTC) Received: by mail-wm0-f54.google.com with SMTP id d66so36146845wmf.0 for ; Wed, 28 Sep 2016 03:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=N4qxIDcd3QhjZHw+lcmB0ieJRXxYbp0IjIJEb312bcI=; b=sNMQZmOEMWCiH087v82eiQRcbIi4myhDPqeh/VyfeQmvCeZsUk3OVbgzcjUaqyarO1 uwyqY6+B485h989TW9++fHLlkP0Usv7ZdWQw3GCdxIX4Q7n3XHhxhEjCWMSFMS1eI2Hy 2YNIsAAviWwm5NzV+9xD9aYIrMBRi2Gla/c0gJnLB8Jl+vPlUO4q9toX0EhCuUn29lok pW/DsR+Fn/Ao/XAMUq7v5UOmcO5ErwSIta42q3r6xXBQj7TRyxmMSip/P4/lHpcGHpwk NCgxeOAzRb0xYXn3anp5CilgoJp2hxYdJ0NoRs59HBJHDsfR1Ei2b7ngQyynqasi10kC /i9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=N4qxIDcd3QhjZHw+lcmB0ieJRXxYbp0IjIJEb312bcI=; b=CV2O+SpfWBtSJG438AOVF9XMWQfI2WScRcdvVcDonE5sgO4Kvu76N20ePmEzhhTeGC 2qXAIe+8Eg0PRt0wyBBjEXBxRRTYlkgLUqdL4jYbk/jAoaMEJ+GzUta+glGPoIaEDiCd j4In0jCo7JqS0wIPmS3UsUWiDBgQJYONd/ceqjz9YTrMNwKAui4I8E+xK4BWP1x2kVt2 XVNwTeRLBCSxPh+2VmWIsdrXCH4C5amO940aJ9IDMbs9bFnE2nVfzbm+LgwKfelzxHlg UFLgw7+FxQehafweBGn7RoUdVseGBKyanoUho6h8qyF9zuBw3vhkykxv2uyqcwzQOtuZ Yy1g== X-Gm-Message-State: AE9vXwO3XHxhQ6NVYDqSik+wSjlDH8o4JnqOC3YUcnCqyrdJ53lEnKZvsZ5fw0gEKRuNSA== X-Received: by 10.194.200.100 with SMTP id jr4mr31735204wjc.137.1475058362829; Wed, 28 Sep 2016 03:26:02 -0700 (PDT) Received: from [127.0.0.1] ([185.120.124.25]) by smtp.gmail.com with ESMTPSA id u72sm8080164wmu.10.2016.09.28.03.26.01 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 03:26:02 -0700 (PDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: [Falcon] Proposal for new ActionScript language feature: Optionally rename an import From: Harbs In-Reply-To: Date: Wed, 28 Sep 2016 13:25:59 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: dev@flex.apache.org X-Mailer: Apple Mail (2.1878.6) archived-at: Wed, 28 Sep 2016 10:26:08 -0000 I like this idea and would propose taking it one step further: Currently transpiled javascript has fully qualified class names for = pretty much everything. This is difficult for closure to minimize = completely. I=92d really like to have some way to =93export=94 class = names as well as =93import=94 to define some compact name for packages. = Based on my playing around, this could save at least tens of KB of JS = downloads. On Sep 27, 2016, at 5:59 PM, Josh Tynjala wrote: > I would like to propose a new feature for the ActionScript language in = the > Apache Flex "Falcon" compiler. It would be nice if developers could > (optionally) rename an import. >=20 > Background > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > Normally when you import a class, you can reference the name of the = class, > without the package (unless there is another class with the same = name): >=20 > // begin example >=20 > import com.example.ImportedClass; >=20 > var example:ImportedClass; >=20 > //end example >=20 > I would like to make it possible to optionally rename the shortened > version, like this: >=20 > // begin example >=20 > import NewName =3D com.example.ImportedClass; >=20 > var test:NewName; >=20 > //end example >=20 > This would make it possible to resolve ambiguities without using the > fully-qualified class name. Consider the following situation that = commonly > comes up when developing Starling apps where the fully-qualified name = is > required for different types of events: >=20 > // begin example >=20 > import flash.events.Event; > import starling.events.Event; >=20 > var one:flash.events.Event; > var two:starling.events.Event; >=20 > // end example >=20 > If we could rename imports, our code wouldn't require cumbersome > fully-qualified names. >=20 > Consider the following example, references to FlashEvent will resolve = to > flash.events.Event and StarlingEvent will resolve to = starling.events.Event: >=20 > // begin example >=20 > import FlashEvent =3D flash.events.Event; > import StarlingEvent =3D starling.events.Event; >=20 > var one:FlashEvent; > var two:StarlingEvent; >=20 > // end example >=20 > In the next example, references to FlashEvent will resolve to > flash.events.Event, similar to the previous example. References to = Event > can resolve to starling.events.Event without ambiguity because > flash.events.Event has been given a different name. >=20 > // begin example >=20 > import FlashEvent =3D flash.events.Event; > import starling.events.Event; >=20 > var one:FlashEvent; > var two:Event; >=20 > // end example >=20 > This would also be useful for transpile-to-JS workflow where the = top-level > package is littered with a ton of HTML classes that may conflict with = names > user-defined classes. For instance, there's a top-level Event class. = There > is no way to specify a different fully-qualified name for things in = the > top-level package, so it's hard to resolve ambiguity when using these > classes. We have a bit of a workaround in Falcon by supporting a fake > "window." package, but that's not ideal. Especially if you consider > Node.js, which doesn't actually have a global window object. >=20 > Risks and Challenges > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > * Renaming imports is a completely optional feature. Anyone can = continue to > code in ActionScript without ever using renamed imports. > * Existing code won't be broken by this new feature. Regular imports = that > don't do any renaming will continue to work the same as they always = have. > * Runtimes like Adobe Flash Player will not need to be modified to = support > renaming imports. Imports are completely resolved at compile-time. > * A SWC compiled from code with renamed imports will work with = compilers > that don't support renaming imports. Again, a SWC contains compiled = code, > so imports were already resolved. > * I have implemented this feature already, in a local branch of = flex-falcon > on my machine. The code already exists, and it works today. >=20 > The one tricky thing is that most IDEs probably won't play well with = code > that uses renamed imports. My NextGenAS extension for VSCode should = have no > problem because it loads the Falcon compiler from the Apache FlexJS = SDK for > its code intelligence features. If Falcon supports it, so will the > extension. Adobe Flash Builder uses ASC 2.0 in a similar way, as I > understand it. With that in mind, Flash Builder won't understand code = with > renamed imports unless Adobe modifies ASC 2.0 to add the same feature. = I > think third-party IDEs (like IntelliJ IDEA and FDT) have their own = code > models (rather than talking to the compiler), so they'd need to make = their > own changes to support this feature too. >=20 > I would like to contact the Flash runtimes team at Adobe and ask if = they'd > be willing to implement this feature in ASC 2.0 too. It's a small = change, > but useful for developer productivity, so it should be well received = by the > community. Additionally, since it will affect the compiler and not the > runtime, it will be significantly less risky for Adobe than other new > language features might be. Finally, considering that the Falcon and = ASC > 2.0 codebases are probably still extremely similar, I wouldn't be = surprised > if the changes were exactly the same. To go back to the previous point > about IDEs, I'm pretty sure that if ASC 2.0 supports this feature, = Flash > Builder will get it for free when someone upgrades the AIR SDK used by = the > FB plugin. There may still be some quirks (I'm curious to see if = organizing > imports breaks or not), but I think ActionScript developers are used = to a > few occasional quirks these days. >=20 > Comments welcome. >=20 > - Josh